JS Built-ins
← Math125 / 215
Mathfroundintermediate

Math.fround() β€” Exact in Float32

πŸ“– Usage Example
// Nearest 32-bit single-precision float
Math.fround(1.337)   // β†’ 1.3370000124...
Math.fround(1.5)     // β†’ 1.5

Use Math.fround() to convert a number to the nearest 32-bit float, useful when working with WebGL or typed arrays.

Math.fround()

Returns the nearest 32-bit single precision float representation of a number.

Challenge: Verify that Math.fround(1.5) is exactly 1.5 since 1.5 is representable in 32-bit float.

πŸ’‘ Hints (1)
  • β€’ 1.5 = 1 + 1/2 is exactly representable in binary floating point