Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31909 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38732 invoked by uid 1010); 26 Aug 2007 03:34:31 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 38716 invoked from network); 26 Aug 2007 03:34:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Aug 2007 03:34:31 -0000 Authentication-Results: pb1.pair.com header.from=ceo@l-i-e.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=ceo@l-i-e.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain l-i-e.com from 67.139.134.202 cause and error) X-PHP-List-Original-Sender: ceo@l-i-e.com X-Host-Fingerprint: 67.139.134.202 o2.hostbaby.com FreeBSD 4.7-5.2 (or MacOS X 10.2-10.3) (2) Received: from [67.139.134.202] ([67.139.134.202:1203] helo=o2.hostbaby.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/13-07349-4C4F0D64 for ; Sat, 25 Aug 2007 23:34:30 -0400 Received: (qmail 64348 invoked by uid 98); 26 Aug 2007 03:34:31 -0000 Received: from 127.0.0.1 by o2.hostbaby.com (envelope-from , uid 1013) with qmail-scanner-2.01 (clamdscan: 0.88.7/4054. Clear:RC:1(127.0.0.1):. Processed in 0.078615 secs); 26 Aug 2007 03:34:31 -0000 Received: from localhost (HELO l-i-e.com) (127.0.0.1) by localhost with SMTP; 26 Aug 2007 03:34:31 -0000 Received: from 209.254.223.2 (SquirrelMail authenticated user ceo@l-i-e.com) by www.l-i-e.com with HTTP; Sat, 25 Aug 2007 22:34:31 -0500 (CDT) Message-ID: <37683.209.254.223.2.1188099271.squirrel@www.l-i-e.com> In-Reply-To: <46CDA789.3080109@googlemail.com> References: <46CDA789.3080109@googlemail.com> Date: Sat, 25 Aug 2007 22:34:31 -0500 (CDT) To: "Zoe Slattery" Cc: internals@lists.php.net Reply-To: ceo@l-i-e.com User-Agent: Hostbaby Webmail MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Subject: Re: [PHP-DEV] Testing math functions From: ceo@l-i-e.com ("Richard Lynch") On Thu, August 23, 2007 10:28 am, Zoe Slattery wrote: > Hi - I've writing a few tests for the math extension and have a > question > about floating point precision. > > Here's a small example: > > --TEST-- > Test return type and value for expected input sin() > --INI-- > precision = 14 > --FILE-- > > $threesixty = pi() * 2.0; > echo "sin 360 = "; > var_dump(sin($threesixty)); > > ?> > --EXPECT-- > sin 360 = float(-2.4492127076448E-16) > > Is it right to test for an exact number in this way? I was slightly > suprised that I got the same number from Windows and Linux (maybe I > shouldn't be). > > If not, I could write the test above to check that sin 360 is zero > plus/minus some small number - but how small? Seems to me that if 'precision' setting is supposed to affect the output of your calculations, then you should, in theory, be able to rely on 14 decimal places, no?... I realize that's an over-simplistic answer, perhaps, and I thought the precision only applied to BC_MATH and/or GMP calculations. I'd be surprised if it was ALWAYS right for every OS, and I strongly suspect it's going to fail on 64-bit hardware big-time. I guess the first question I have is "What precisely are you testing?" The 'precision' setting? Or just that sin(2 * M_PI) is kinda sorta close to 0? If you just want "close to 0" then double the answer you are getting now, and call that "close enough" :-) If you think 'precision' is supposed to affect it and guarantee 14 decimal places of precision, then 1.0E-14 to 1.0E14 should be your range, no? -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?