Re: [RFC] Safe Casting Functions

From: Date: Fri, 24 Oct 2014 18:06:27 +0000
Subject: Re: [RFC] Safe Casting Functions
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-78308@lists.php.net to get a copy of this message
On 24.10.2014 01:53, Andrea Faulds wrote: >> On 23 Oct 2014, at 20:50, Marc Bennewitz <php@mabe.berlin> wrote: >> >> You addresses data loss on convert float to int. >> Do you also address data loss on int to float? >> >> |to_float(||9223372036854774784) -> pass |as it results in >> 9223372036854774784 >> |to_float(|||9223372036854774785|) -> |fail as it results in >> 9223372036854774784 > Floats aren’t expected to be precise, so I don’t see why this shouldn’t pass. It’s a > loss of data, sure, but merely of precision, which is expected here. The reason I have to_int fail > is because float overflow to int completely mangles your input. > ... It’s a loss of data ... And that is the point! If you don't care about loss of data we have more than enough functions including default casting (float) operator to cast to float. > -- > Andrea Faulds > http://ajf.me/ > > > > >

« previous php.internals (#78308) next »