Bug #79641 [Com]: Type cast problem

From: Date: Wed, 27 May 2020 12:25:26 +0000
Subject: Bug #79641 [Com]: Type cast problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227199@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79641&edit=1 ID: 79641 Comment by: mr dot vladkuz at gmail dot com Reported by: mr dot vladkuz at gmail dot com Summary: Type cast problem Status: Not a bug Type: Bug Package: *General Issues Operating System: Centos 7, macos PHP Version: 7.4.6 Block user comment: N Private report: N New Comment: This problem present for range digits from 4096,11 to 5241,98 Previous Comments: ------------------------------------------------------------------------ [2020-05-27 12:13:37] requinix@php.net 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://www.floating-point-gui.de/ Thank you for your interest in PHP. ------------------------------------------------------------------------ [2020-05-27 12:12:30] mr dot vladkuz at gmail dot com Description: ------------ One bit is lost when using typed parameters function. This occurs for 2^18-2^19. Test script: --------------- class TypeHintEvil { private $num; public function getNum(): int { return $this->num; } public function setNum(int $num): void { $this->num = $num; } } $evil = new TypeHintEvil(); $evil->setNum(4860.98 * 100); echo $evil->getNum(); //486097 Expected result: ---------------- 486098 Actual result: -------------- 486097 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79641&edit=1

« previous php.bugs (#227199) next »