abs()
abs()
returns the absolute value of a number. There is a method function and a static method function.
Syntax
method function
ba.abs();
static method function
BigArith.abs(n);
Parameters
method function
none
static method function
n - Required - {string|number|BigArith}
The number to find the absolute value of. It could be a string of digits, a number, or a BigArith object
Return value
method function - {BigArith}
A BigArith object with its value equals to absolute value of the BigArith object it is called on.
static method function - {BigArith}
A BigArith object with its value equals to absolute value of n.
Description
There are two functions which could be used, the method function, and the static method function. The method function takes no parameter and returns the absolute value of the BigArith object it is called on.
The static method function takes a parameter n and is always used as BigArith.abs()
. It returns the absolute value of n.
Any number parameter (that is not strings of digits or a BigArith) should be between the
Number.MIN_SAFE_INTEGER
andNumber.MAX_SAFE_INTEGER
limits.
Examples
In the server-side, always remember to add the line
var BigArith = require('bigarith.js');
however every other thing remains the same in both server-side and client-side code.
Using method function
var ba = new BigArith("-17031986");
ba = ba.abs(); //BigArith object with value "17031986"
ba = new BigArith("+17031986");
ba = ba.abs(); //BigArith object with value "17031986"
ba = new BigArith(null);
ba = ba.abs(); //BigArith object with value "0"
Using the static method function
var ba = BigArith.abs("-17031986"); //BigArith object with value "17031986"
ba = BigArith.abs("+17031986"); //BigArith object with value "17031986"
ba = BigArith.abs(null); //BigArith object with value "0"
ba = BigArith.abs(); //BigArith object with value "0"
ba = BigArith.abs(NaN); //NaN
More examples here. Full documentation here