nv-number-big
v1.0.1
Published
nv-number-big =============== - nv-number-big
Downloads
2
Readme
nv-number-big
nv-number-big
its SLOW, just for nvlang test, to output a special-float-format
nvlang not support float(coz its runtime is txt-file) , div(/)has highest precedence
install
- npm install nv-number-big
usage
const x = require("nv-number-big")
syntax:
<->? [0-9]* <.>? [0-9]* <r>? [0-9]*
0.r3 means 0.33333.....
1.11r123 means 1.11_123_123_123.......
example
parse
> x.parse('0.r3')
R [1/3] {}
> x.parse('.r3')
R [1/3] {}
> x.parse('1.r3')
R [4/3] {}
>
> x.parse('2.33r2')
R [2099/900] {}
>
> 2099/900
2.332222222222222
>
> x.parse('0.r3')
R [1/3] {}
>
> x.parse('1234567893343.33333')
R [123456789334333333/100000] {}
>
> x.parse('1234567893343.r3')
R [3703703680030/3] {}
>
div lit_div IS very slow FOR big num
var r0 = x.parse('3.2')
var r1 = x.parse('2.1')
> r0
R [16/5] {}
> r1
R [21/10] {}
>
> r0.float_str()
'3.2'
> r1.float_str()
'2.1'
>
> x.div(r0,r1)
R [32/21] {}
>
> x.div(r0,r1).float_str()
'1.r523809'
>
> 32/21
1.5238095238095237
> 1.523809_523809_5237
1.5238095238095237
>
> x.lit_div('.r6','.25')
'2.r6'
>
> 2/3
0.6666666666666666
> 1/4
0.25
>
> Number.MAX_SAFE_INTEGER
9007199254740991
>
var r0 = x.parse('9007199254740992_9007199254740992.1234555')
var r1 = x.parse('9007199254740992_9007199254740992.25')
var r = x.div(r0,r1)
>
R [180143985094819858014398509481984246911/180143985094819858014398509481984500000] {}
>
//if number too big ,dont USE .float_str, very slow
var r = x.lit_div('9007199254740992.r3','1.234567')
> r
'7295836722301011.r069738080908799063423316..........46094082648' ... 24039 more characters
mul
> x.lit_mul('9007199254740992_9007199254740992.1234555','9007199254740992_9007199254740992.25')
'8112963841460669792171668806540148683299530277210438137106422988.568719875'
>
> x.lit_mul('9007199254740992.r3','1.234567',".r6")
'7413327308218548.45465r7'
>
> x.lit_mul('9007199254740992.r3','1.234567',".r6","123","4455")
'4062243898447976903956.42743'
>
> x.parse('4062243898447976903956.42743')
R [406224389844797690395642743/100000] {}
>
add
> x.lit_add("0.r3","0.25","0.2","0.1r6")
'0.95'
>
> 1/3+1/4+1/5+1/6
0.9499999999999998
>
> 1/3+1/6 +1/4+1/5
0.95
>
sub
> x.lit_sub("0.r3","0.5")
'-0.1r6'
>
> x.lit_sub("0.r3","0.5","-0.5")
'0.r3'
>
APIS
{
qr: [Function: qr],
ERRORS: ParseError(4) {
'must_start_with_digit_or_dot_or_neg',
'must_follow_with_digit_or_r',
'must_follow_with_digit',
'neg_can_only_at_start'
},
parse: [Function: parse],
R: [class R],
div: [Function: div],
add: [Function: add],
sub: [Function: sub],
mul: [Function: mul],
lit_div: [Function: lit_div],
lit_add: [Function: lit_add],
lit_sub: [Function: lit_sub],
lit_mul: [Function: lit_mul]
}
METHODS
r.abs r.add r.clone r.constructor
r.d_ r.div r.eq r.fac
r.float_str r.ge r.gt r.inv
r.is_neg r.is_one r.is_zero r.le
r.lt r.mul r.n_ r.neg
r.neq r.pow r.sub
LICENSE
- ISC