prog8/examples/bench8/pow.p8

43 lines
831 B
Plaintext
Raw Normal View History

2022-08-12 20:02:44 +00:00
%import textio
%import floats
main {
const ubyte N_ITER = 10
const ubyte SIZE = 32
float[SIZE] array = 0.0
sub testpow(float x, uword y) -> float {
float tmp = x
if y==0
return 1
repeat y-1 {
tmp *= x
}
return tmp
}
sub start() {
txt.print("calculating (expecting 3.614007e+12)...\n")
cbm.SETTIM(0,0,0)
2022-08-12 20:02:44 +00:00
float res=0.0
2022-08-12 20:02:44 +00:00
uword i
ubyte j
for i in 0 to N_ITER-1 {
for j in 0 to SIZE-1 {
array[j] += testpow(2.5/(i+1.0), j)
}
}
for j in 0 to SIZE-1 {
res += array[j]
}
floats.print_f(res)
txt.nl()
2023-09-05 20:59:36 +00:00
floats.print_f(cbm.RDTIM16() / 60.0)
txt.print(" seconds")
sys.wait(9999)
2022-08-12 20:02:44 +00:00
}
}