implement bigint
This commit is contained in:
21
main.ua
Normal file
21
main.ua
Normal file
@@ -0,0 +1,21 @@
|
||||
# bigint
|
||||
|
||||
# base -- internal representation of number
|
||||
β ← 1e9
|
||||
|
||||
# add two little-endian digital bigints
|
||||
# ? b1 b2
|
||||
Add ← (
|
||||
˜⊂0⬚0+ # fill-add and expand digits
|
||||
⍥(+↻¯1⊃(⌊÷)◿β)∞ # carry calc
|
||||
⍜⇌(⍥↘₁=0⊸⊢) # trim trailing zeroes
|
||||
)
|
||||
|
||||
# repeated addition of two little-endian digital bigints
|
||||
# ? multiplier multiplicand
|
||||
Mult ← ⍥Add⌝⊥β ⊙(⊥β0)
|
||||
|
||||
┌─╴test
|
||||
⍤⤙≍ ⊙+◡(⌝⊥β Add ∩(⊥β)) 10000000000000 10000000000000
|
||||
⍤⤙≍ ⊙×◡(⌝⊥β Mult ∩(⊥β)) 3 7
|
||||
└─╴
|
||||
Reference in New Issue
Block a user