Re: [RFC] [DISCUSSION] Scalar Pseudo-type

From: Date: Fri, 29 Dec 2017 17:21:32 +0000
Subject: Re: [RFC] [DISCUSSION] Scalar Pseudo-type
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-101444@lists.php.net to get a copy of this message
Am 29.12.2017 um 18:18 schrieb Fleshgrinder:
On 12/29/2017 4:09 PM, lists@rhsoft.net wrote:
Am 29.12.2017 um 13:08 schrieb Fleshgrinder:
What is the use case for int|float? I mean, if f is able to process a float than f is able to process an int and since int is already automatically changed to a float, well, you're done
just read the mass of bugreports caused by float answered with the default paragraph below and you know why you don't want your int-values silently converted to a float 7 may become to 7.000000000000000001 or something similar and "$x === 7" may also fail wile the argument was int 7 ________________________ 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/
Obviously but this does not answer anything. You expect an int or a float, hence, you need to be prepared to handle floats. Your 7 example is the best illustration. You need to handle those situations in your script with the appropriate strategy for your domain (rounding, truncation, floor, ...)
no, when i accept "int|float" i don't get something converted at all and i can handle the cases different - when it#s silently casted to a float i have no way to know it was a int at call time

« previous php.internals (#101444) next »