Bug #52324 [Bgs]: bad result when adding two floats

2010-07-12 Thread brunog at micro-examples dot com
Edit report at http://bugs.php.net/bug.php?id=52324edit=1

 ID:   52324
 User updated by:  brunog at micro-examples dot com
 Reported by:  brunog at micro-examples dot com
 Summary:  bad result when adding two floats
 Status:   Bogus
 Type: Bug
 Package:  *General Issues
 Operating System: ubuntu
 PHP Version:  5.2.14RC2

 New Comment:

thank you for the quick reply

adding ini_set('precision',16); does not give correct result value :

0.0



is it an echo() bug ?

0.0: is lexicographically before 0.1

0.09 + 0.01 = 0.0: is correct ascii saying


Previous Comments:

[2010-07-13 00:39:21] ras...@php.net

prints 0.1 for me.  You are probably hitting a floating point limitation
combined 

with a precision setting problem in your environment.  Try adding 

ini_set('precision',16); to the top of your script and you will see.


[2010-07-13 00:35:04] brunog at micro-examples dot com

Description:

PHP Version = 5.2.4-2ubuntu5.10

can you please consider this short code ?

Test script:
---
?php

$f1 = 0.09 ;

$f2 = 0.01 ;

$tot = $f1 + $f2 ;

echo($tot\n) ;

?



Expected result:

0.1



Actual result:
--
0.0:






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52324edit=1


Bug #52324 [Bgs]: bad result when adding two floats

2010-07-12 Thread rasmus
Edit report at http://bugs.php.net/bug.php?id=52324edit=1

 ID:   52324
 Updated by:   ras...@php.net
 Reported by:  brunog at micro-examples dot com
 Summary:  bad result when adding two floats
 Status:   Bogus
 Type: Bug
 Package:  *General Issues
 Operating System: ubuntu
 PHP Version:  5.2.14RC2

 New Comment:

That is the correct value according to how computers store floating
point 

values.  If you want it accurate to 2 decimal places, round() it to 2
decimal 

places.  Read the big red warning box here: 

http://php.net/manual/en/language.types.float.php


Previous Comments:

[2010-07-13 00:58:02] brunog at micro-examples dot com

thank you for the quick reply

adding ini_set('precision',16); does not give correct result value :

0.0



is it an echo() bug ?

0.0: is lexicographically before 0.1

0.09 + 0.01 = 0.0: is correct ascii saying


[2010-07-13 00:39:21] ras...@php.net

prints 0.1 for me.  You are probably hitting a floating point limitation
combined 

with a precision setting problem in your environment.  Try adding 

ini_set('precision',16); to the top of your script and you will see.


[2010-07-13 00:35:04] brunog at micro-examples dot com

Description:

PHP Version = 5.2.4-2ubuntu5.10

can you please consider this short code ?

Test script:
---
?php

$f1 = 0.09 ;

$f2 = 0.01 ;

$tot = $f1 + $f2 ;

echo($tot\n) ;

?



Expected result:

0.1



Actual result:
--
0.0:






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52324edit=1


Bug #52324 [Bgs]: bad result when adding two floats

2010-07-12 Thread brunog at micro-examples dot com
Edit report at http://bugs.php.net/bug.php?id=52324edit=1

 ID:   52324
 User updated by:  brunog at micro-examples dot com
 Reported by:  brunog at micro-examples dot com
 Summary:  bad result when adding two floats
 Status:   Bogus
 Type: Bug
 Package:  *General Issues
 Operating System: ubuntu
 PHP Version:  5.2.14RC2

 New Comment:

maybe, but 0.0: is not a correct value at all as an add result, whatever
floating point accuracy is

0.09 + 0.02 gives 0.11 as expected, neither 0.1099 nor 0.::


Previous Comments:

[2010-07-13 01:04:36] ras...@php.net

That is the correct value according to how computers store floating
point 

values.  If you want it accurate to 2 decimal places, round() it to 2
decimal 

places.  Read the big red warning box here: 

http://php.net/manual/en/language.types.float.php


[2010-07-13 00:58:02] brunog at micro-examples dot com

thank you for the quick reply

adding ini_set('precision',16); does not give correct result value :

0.0



is it an echo() bug ?

0.0: is lexicographically before 0.1

0.09 + 0.01 = 0.0: is correct ascii saying


[2010-07-13 00:39:21] ras...@php.net

prints 0.1 for me.  You are probably hitting a floating point limitation
combined 

with a precision setting problem in your environment.  Try adding 

ini_set('precision',16); to the top of your script and you will see.


[2010-07-13 00:35:04] brunog at micro-examples dot com

Description:

PHP Version = 5.2.4-2ubuntu5.10

can you please consider this short code ?

Test script:
---
?php

$f1 = 0.09 ;

$f2 = 0.01 ;

$tot = $f1 + $f2 ;

echo($tot\n) ;

?



Expected result:

0.1



Actual result:
--
0.0:






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52324edit=1


Bug #52324 [Bgs]: bad result when adding two floats

2010-07-12 Thread rasmus
Edit report at http://bugs.php.net/bug.php?id=52324edit=1

 ID:   52324
 Updated by:   ras...@php.net
 Reported by:  brunog at micro-examples dot com
 Summary:  bad result when adding two floats
 Status:   Bogus
 Type: Bug
 Package:  *General Issues
 Operating System: ubuntu
 PHP Version:  5.2.14RC2

 New Comment:

It doesn't show 0.0 on any PHP version I have access to.  No idea about
your 

5.2.4.  That's from 3 years ago.  I don't have anything that old on any
of my 

machines.


Previous Comments:

[2010-07-13 01:10:58] brunog at micro-examples dot com

maybe, but 0.0: is not a correct value at all as an add result, whatever
floating point accuracy is

0.09 + 0.02 gives 0.11 as expected, neither 0.1099 nor 0.::


[2010-07-13 01:04:36] ras...@php.net

That is the correct value according to how computers store floating
point 

values.  If you want it accurate to 2 decimal places, round() it to 2
decimal 

places.  Read the big red warning box here: 

http://php.net/manual/en/language.types.float.php


[2010-07-13 00:58:02] brunog at micro-examples dot com

thank you for the quick reply

adding ini_set('precision',16); does not give correct result value :

0.0



is it an echo() bug ?

0.0: is lexicographically before 0.1

0.09 + 0.01 = 0.0: is correct ascii saying


[2010-07-13 00:39:21] ras...@php.net

prints 0.1 for me.  You are probably hitting a floating point limitation
combined 

with a precision setting problem in your environment.  Try adding 

ini_set('precision',16); to the top of your script and you will see.


[2010-07-13 00:35:04] brunog at micro-examples dot com

Description:

PHP Version = 5.2.4-2ubuntu5.10

can you please consider this short code ?

Test script:
---
?php

$f1 = 0.09 ;

$f2 = 0.01 ;

$tot = $f1 + $f2 ;

echo($tot\n) ;

?



Expected result:

0.1



Actual result:
--
0.0:






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52324edit=1


Bug #52324 [Bgs]: bad result when adding two floats

2010-07-12 Thread brunog at micro-examples dot com
Edit report at http://bugs.php.net/bug.php?id=52324edit=1

 ID:   52324
 User updated by:  brunog at micro-examples dot com
 Reported by:  brunog at micro-examples dot com
 Summary:  bad result when adding two floats
 Status:   Bogus
 Type: Bug
 Package:  *General Issues
 Operating System: ubuntu
 PHP Version:  5.2.14RC2

 New Comment:

strangely it works fine on an older php version 

PHP Version = 5.1.6

gives 0.1 as expected


Previous Comments:

[2010-07-13 01:16:39] ras...@php.net

It doesn't show 0.0 on any PHP version I have access to.  No idea about
your 

5.2.4.  That's from 3 years ago.  I don't have anything that old on any
of my 

machines.


[2010-07-13 01:10:58] brunog at micro-examples dot com

maybe, but 0.0: is not a correct value at all as an add result, whatever
floating point accuracy is

0.09 + 0.02 gives 0.11 as expected, neither 0.1099 nor 0.::


[2010-07-13 01:04:36] ras...@php.net

That is the correct value according to how computers store floating
point 

values.  If you want it accurate to 2 decimal places, round() it to 2
decimal 

places.  Read the big red warning box here: 

http://php.net/manual/en/language.types.float.php


[2010-07-13 00:58:02] brunog at micro-examples dot com

thank you for the quick reply

adding ini_set('precision',16); does not give correct result value :

0.0



is it an echo() bug ?

0.0: is lexicographically before 0.1

0.09 + 0.01 = 0.0: is correct ascii saying


[2010-07-13 00:39:21] ras...@php.net

prints 0.1 for me.  You are probably hitting a floating point limitation
combined 

with a precision setting problem in your environment.  Try adding 

ini_set('precision',16); to the top of your script and you will see.




The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

http://bugs.php.net/bug.php?id=52324


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52324edit=1