Edit report at http://bugs.php.net/bug.php?id=51547&edit=1

 ID:          51547
 Updated by:  degeb...@php.net
 Reported by: acollins at liv dot ac dot uk
 Summary:     Type casting from int to int after log changes value
-Status:      Open
+Status:      Bogus
 Type:        Bug
 Package:     *Math Functions
 PHP Version: 5.2.13

 New Comment:

Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

Try having a look at this:

echo serialize(log(1000, 10));



When you cast to int you just truncate the fractional part.


Previous Comments:
------------------------------------------------------------------------
[2010-04-13 11:04:47] acollins at liv dot ac dot uk

Note: I assume this is because log() returns a floating point value.
I.e. it's a precision issue?

------------------------------------------------------------------------
[2010-04-13 11:03:32] acollins at liv dot ac dot uk

Description:
------------
When performing a log(), and immediately type casting afterwards, the
value changes.

Test script:
---------------
<?php

$val = 1000;

echo log($val, 10) .' == '. (int) log($val, 10);

?>

Expected result:
----------------
3 == 3

Actual result:
--------------
3 == 2


------------------------------------------------------------------------



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

Reply via email to