modf.php
Table of Contents
Functions
- modf() : array{0: float, 1: float}
- Splits a number into its integral and fractional parts, like the C `modf()` function.
Functions
modf()
Splits a number into its integral and fractional parts, like the C `modf()` function.
modf(float $number) : array{0: float, 1: float}
The number is truncated toward zero, so the sign is preserved on both parts :
modf( -1.5 ) returns [ -1.0 , -0.5 ] (and not [ -2.0 , 0.5 ] as a floor()
based split would). Both parts are always returned as float.
Special values follow the C behavior :
modf( INF )returns[ INF , 0.0 ](idem with-INF).modf( NAN )returns[ NAN , NAN ].
Note: unlike C's and Python's modf, the integral part comes first
(natural reading order : 1.5 is 1 + 0.5), the fractional part second.
Parameters
- $number : float
-
The number to split.
Tags
Return values
array{0: float, 1: float} —A two-element array : [ integral part , fractional part ].