Last Updated : 08 Aug, 2023
What is a Safe Integer?
A safe integer is an integer that has the following properties
What is an IEEE-754 double-precision number?
Double-precision floating-point format is a computer number format, which occupies 64 bits in computer memory. It represents a wide range of numeric values by using a floating-point.
The IEEE 754 standard specifies a binary64 as having:
isSafeInteger() Method In JavaScript: The isSafeInteger() method in JavaScript is used to check whether a number is a safe integer or not.
Syntax:
Number.isSafeInteger(Value)
Parameters:
Return Value: The toExponential() method in JavaScript returns true if the value is a safe integer Number, else it returns false.
Below are examples of the Number isSafeInteger() Method.
Example 1: This example uses the safeinteger() method to check if 4 is a safe integer or not.
JavaScript
console.log("Output : " + Number.isSafeInteger(44));
Example 2: Passing a positive number as an argument in the isSafeInteger() method.
JavaScript
console.log("Output : " + Number.isSafeInteger(23));
Example 3: Passing a negative number as an argument in the isSafeInteger() method.
JavaScript
console.log("Output : " + Number.isSafeInteger(-23));
Example 4: Passing a number(with decimals) as an argument in the isSafeInteger() method.
JavaScript
console.log("Output : " + Number.isSafeInteger(0.5));
Example 5: Passing an equation( which equates to an infinite value) as an argument in the isSafeInteger() method.
JavaScript
console.log("Output : " + Number.isSafeInteger(0 / 0));
Code Explanation: JavaScript uses double-precision floating-point format numbers as specified in IEEE 754 and can only safely represent numbers between -(253 - 1) and 253 - 1. If the parameter passed lies in this specified range then the number.isSafeInteger() method returns true else false.
We have a complete list of Javascript Number Methods, to check those please go through the Javascript Number Complete Reference article.
Supported Browsers:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4