Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78309 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43633 invoked from network); 24 Oct 2014 18:14:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2014 18:14:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:58360] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/48-31309-9F69A445 for ; Fri, 24 Oct 2014 14:14:17 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 311B424015F; Fri, 24 Oct 2014 14:14:05 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id fNM8pPz6IO6r; Fri, 24 Oct 2014 14:14:05 -0400 (EDT) Received: from oa-edu-168-67.wireless.abdn.ac.uk (oa-edu-168-67.wireless.abdn.ac.uk [137.50.168.67]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id B558E240142; Fri, 24 Oct 2014 14:13:38 -0400 (EDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <544A9523.6010104@mabe.berlin> Date: Fri, 24 Oct 2014 19:13:34 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <6D2E5BCF-F26A-4854-AA6D-FA85672FB683@ajf.me> References: <66B7B28C-2651-4A71-AC2A-55D4C7BB3DDC@ajf.me> <544959B8.20207@mabe.berlin> <54495C0F.9080404@mabe.berlin> <544A9523.6010104@mabe.berlin> To: Marc Bennewitz X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] [RFC] Safe Casting Functions From: ajf@ajf.me (Andrea Faulds) > On 24 Oct 2014, at 19:06, Marc Bennewitz wrote: >=20 >=20 > On 24.10.2014 01:53, Andrea Faulds wrote: >>> On 23 Oct 2014, at 20:50, Marc Bennewitz wrote: >>>=20 >>> You addresses data loss on convert float to int. >>> Do you also address data loss on int to float? >>>=20 >>> |to_float(||9223372036854774784) -> pass |as it results in >>> 9223372036854774784 >>> |to_float(|||9223372036854774785|) -> |fail as it results in >>> 9223372036854774784 >> Floats aren=92t expected to be precise, so I don=92t see why this = shouldn=92t pass. It=92s 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=92s 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. Floats are special, they are not expected to be precise. If we reject = this, then perhaps we should also reject 0.1, because it can=92t be = precisely represented by a float? -- Andrea Faulds http://ajf.me/