|Perl Language Reference Manual|
by Larry Wall and others
Paperback (6"x9"), 724 pages
RRP £29.95 ($39.95)
Sales of this book support The Perl Foundation! Get a printed copy>>>
6.2 Numeric operators and numeric conversions
As mentioned earlier, Perl can store a number in any one of three formats, but most operators typically understand only one of those formats. When a numeric value is passed as an argument to such an operator, it will be converted to the format understood by the operator.
Six such conversions are possible:
native integer --> native floating point (*) native integer --> decimal string native floating_point --> native integer (*) native floating_point --> decimal string (*) decimal string --> native integer decimal string --> native floating point (*)
These conversions are governed by the following general rules:
- If the source number can be represented in the target form, that representation is used.
- If the source number is outside of the limits representable in the target form, a representation of the closest limit is used. (Loss of information)
- If the source number is between two numbers representable in the target form, a representation of one of these numbers is used. (Loss of information)
native floating point --> native integerconversions the magnitude of the result is less than or equal to the magnitude of the source. ("Rounding to zero".)
decimal string --> native integerconversion cannot be done without loss of information, the result is compatible with the conversion sequence
decimal_string --> native_floating_point --> native_integer. In particular, rounding is strongly biased to 0, though a number like
"0.99999999999999999999"has a chance of being rounded to 1.
RESTRICTION: The conversions marked with
(*) above involve steps
performed by the C compiler. In particular, bugs/features of the compiler
used may lead to breakage of some of the above rules.
|ISBN 9781906966027||Perl Language Reference Manual||See the print edition|