Numbers.isUnsafeFloat()

Syntax

function isUnsafeFloat(value: number): boolean

Checks if a number is an “unsafe” floating point number, that is whether it is likely to suffer from floating point inaccuracies.

Parameters
value

A number which may or may not be a floating point number.

Example

import { Numbers } from 'potence';

Numbers.isUnsafeFloat(0.1);  // -> true
Numbers.isUnsafeFloat(0.5);  // -> false

Remarks

This function tests for floating point inaccuracy by conducting an arbitrary mathematical operation on the value, inverting it, and comparing it with the original value. As a result, this function only returns a “guess”. You should not base any important conditions off the result of this function.

This function always returns false for NaN, Infinity, and -Infinity.

To compare floating point numbers, use Numbers.compare() instead. Its page also offers a more detailed explanation of floating point inaccuracies.

Contrast Numbers.isSafeFloat().