JS.BigInt
- Package
- purescript-js-bigints
- Repository
- purescript-contrib/purescript-js-bigints
#fromNumber Source
fromNumber :: Number -> Maybe BigIntConvert a Number to a BigInt. The fractional part is truncated.
#fromString Source
fromString :: String -> Maybe BigIntParse a string into a BigInt. Returns Nothing if the parse fails.
Supports decimal, binary, octal, hexadecimal and exponentiation notations.
See MDN for more examples.
Examples:
fromString "857981209301293808359384092830482" -- 857981209301293808359384092830482
fromString "0b10000000000000000000000000000000" -- 2147483648
fromString "0B00000000011111111111111111111111" -- 8388607
fromString "0O755" -- 493
fromString "0o644" -- 420
fromString "0xFFFFFFFFFFFFFFFFF" -- 295147905179352830000
fromString "0XA" -- 10
fromString "0e-5" -- 0
fromString "5e1" -- 50
fromString "175e-2" -- 1.75
fromString "1E3" -- 1000
#fromStringAs Source
fromStringAs :: Radix -> String -> Maybe BigIntLike fromString, but the integer can be specified in a different base.
Example:
fromStringAs binary "100" == Just 4
fromStringAs hexadecimal "ff" == Just 255
#toInt Source
toInt :: BigInt -> Maybe IntConvert a BigInt to an Int.
If the BigInt is larger than 2_147_483_647 or smaller than -2_147_483_648 then Nothing is returned.
#toNumber Source
toNumber :: BigInt -> NumberConvert a BigInt to a Number.
There may be a loss of precision.
If the BigInt is larger than 9_007_199_254_740_991 then the result will be +Infinity. If the BigInt is smaller than -9_007_199_254_740_991 then the result will be -Infinity.
#toStringAs Source
toStringAs :: Radix -> BigInt -> StringLike toString, but the integer can be specified in a different base.
#shr Source
shr :: BigInt -> BigInt -> BigIntThe BigInt in the first argument shifted to the right by the number of bits specified in the second argument. Excess bits shifted off to the right are discarded, and copies of the leftmost bit are shifted in from the left. This operation is also called "sign-propagating right shift" or "arithmetic right shift", because the sign of the resulting number is the same as the sign of the first operand.
Re-exports from Data.Int
#Radix Source
newtype RadixThe number of unique digits (including zero) used to represent integers in a specific base.
#Parity Source
data ParityA type for describing whether an integer is even or odd.
The Ord instance considers Even to be less than Odd.
The Semiring instance allows you to ask about the parity of the results
of arithmetical operations, given only the parities of the inputs. For
example, the sum of an odd number and an even number is odd, so
Odd + Even == Odd. This also works for multiplication, eg. the product
of two odd numbers is odd, and therefore Odd * Odd == Odd.
More generally, we have that
parity x + parity y == parity (x + y)
parity x * parity y == parity (x * y)
for any integers x, y. (A mathematician would say that parity is a
ring homomorphism.)
After defining addition and multiplication on Parity in this way, the
Semiring laws now force us to choose zero = Even and one = Odd.
This Semiring instance actually turns out to be a Field.
Constructors
Instances
#hexadecimal Source
hexadecimal :: RadixThe base-16 system.
- Modules
- JS.
BigInt