1
1
mirror of https://github.com/anoma/juvix.git synced 2024-11-30 14:13:27 +03:00
juvix/tests/Core/positive/test036.jvc
2022-12-06 11:33:20 +01:00

101 lines
2.2 KiB
Plaintext

-- big numbers
def power' := \x \y \acc
if y = 0 then
acc
else
power' x (y - 1) (x * acc);
def power := \x \y power' x y 1;
def neg := \x 0 - x;
def num1 := 1267650600228229401496703205376;
def num2 := neg 126765060022822940149670320537674809325432;
def sqrt' := \x \top \bot
if top - bot <= 1 then
bot
else
let y := (top + bot) / 2
in
if y * y > x then
sqrt' x y bot
else
sqrt' x top y;
def sqrt := \x sqrt' x (x + 1) 0;
def log' := \x \y \acc
if y = 1 then
acc
else
log' x (y / x) (acc + 1);
def log := \x \y log' x y 0;
def fast_power' := \x \y \acc
if y = 0 then
acc
else if y % 2 = 0 then
fast_power' (x * x) (y / 2) acc
else
fast_power' (x * x) (y / 2) (x * acc);
def fast_power := \x \y fast_power' x y 1;
def writeLn := \x write x >> write "\n";
writeLn num1 >>
writeLn num2 >>
writeLn (num1 + num2) >>
writeLn (num1 - num2) >>
writeLn (num1 * num2) >>
writeLn (num2 / num1) >>
writeLn (num2 % num1) >>
writeLn "" >>
writeLn (power 2 30) >>
writeLn (power 2 31) >>
writeLn (power 2 32) >>
writeLn (power 2 62) >>
writeLn (power 2 63) >>
writeLn (power 2 64) >>
writeLn (power 2 100) >>
writeLn (power (neg 2) 30) >>
writeLn (power (neg 2) 31) >>
writeLn (power (neg 2) 32) >>
writeLn (power (neg 2) 62) >>
writeLn (power (neg 2) 63) >>
writeLn (power (neg 2) 64) >>
writeLn (power (neg 2) 101) >>
writeLn "" >>
writeLn (sqrt (power 2 128)) >>
writeLn (sqrt (power 3 180)) >>
writeLn (sqrt (power num1 2)) >>
writeLn (sqrt (power num2 2)) >>
writeLn "" >>
writeLn (log 2 (power 2 100)) >>
writeLn (log 20 (power 20 100)) >>
writeLn (log 9 (power 3 100)) >>
writeLn "" >>
writeLn (fast_power 2 30) >>
writeLn (fast_power 2 31) >>
writeLn (fast_power 2 32) >>
writeLn (fast_power 2 62) >>
writeLn (fast_power 2 63) >>
writeLn (fast_power 2 64) >>
writeLn (fast_power 2 100) >>
writeLn (fast_power (neg 2) 30) >>
writeLn (fast_power (neg 2) 31) >>
writeLn (fast_power (neg 2) 32) >>
writeLn (fast_power (neg 2) 62) >>
writeLn (fast_power (neg 2) 63) >>
writeLn (fast_power (neg 2) 64) >>
writeLn (fast_power (neg 2) 101) >>
writeLn "" >>
writeLn (fast_power 2 1000) >>
writeLn (fast_power 3 1000) >>
writeLn (fast_power 2 10000) >>
writeLn (fast_power 2 100000)