Bug #67257 [NEW]: Edge case error when casting to integer

From: Date: Mon, 12 May 2014 11:24:31 +0000
Subject: Bug #67257 [NEW]: Edge case error when casting to integer
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185775@lists.php.net to get a copy of this message
From:             cc at altruja dot de
Operating system: Linux
PHP version:      Irrelevant
Package:          *General Issues
Bug Type:         Bug
Bug description:Edge case error when casting to integer

Description:
------------
There seems to be an oddity in an edge case of casting float to integer
after multiplying it with a multiple of 10. It only seems to occur with
.4 after the decimal point, and only between 256.4 and 328.4. 

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

var_dump((integer) (255.4 * 100));
var_dump((integer) (256.4 * 100));
var_dump((integer) (256.3 * 100));
var_dump((integer) (327.4 * 100));
var_dump((integer) (328.4 * 100));

Expected result:
----------------
int(25540)
int(25640)
int(25630)
int(32740)
int(32840)

Actual result:
--------------
int(25540)
int(25639)
int(25630)
int(32739)
int(32840)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=67257&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=67257&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=67257&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=67257&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=67257&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=67257&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=67257&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=67257&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=67257&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=67257&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=67257&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=67257&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=67257&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=67257&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67257&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=67257&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=67257&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=67257&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67257&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=67257&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=67257&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#185775) next »