-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecay.js
More file actions
46 lines (35 loc) · 848 Bytes
/
decay.js
File metadata and controls
46 lines (35 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {isBigInt as isIntN} from '../mod/type check'
import {signabs} from '../mod/std'
/**
Division by repeated subtraction, but the divisor gets decremented each iteration
*/
export const decayDiv = (n, d) => {
[n, d] = [signabs(n), signabs(d)]
let i = isIntN(n[0]) ? 0n : 0
while (n[1] > d[1]) {
n[1] -= d[1]--
i++
}
//quotient, remainder, and unnamed, lol
return [n[0] * i, n[0] * n[1], d[0] * d[1]]
}
/**
Multiplication by repeated addition, but multiplier gets decremented
*/
export const decayMult0 = (f, d) => {
[f, d] = [signabs(f), signabs(d)]
if (!f[0] || !d[0])
return f[0] * d[0]
let i = isIntN(d[0]) ? 0n : 0, n = f[1]
while (i < d[1]) {
n += f[1]
d[1]--
i++
}
return [n[0] * i, n[0] * n[1], d[0] * d[1]]
}
/*to-do, lol
//"multiplicand" (factor) gets decremented
const decayMult1 = (f, m) => {
}
*/