2022-04-23 02:15:51 +02:00
|
|
|
; Prog8 definitions for floating point handling on the VirtualMachine
|
|
|
|
|
|
|
|
%option enable_floats
|
|
|
|
|
|
|
|
floats {
|
|
|
|
|
|
|
|
const float PI = 3.141592653589793
|
|
|
|
const float TWOPI = 6.283185307179586
|
|
|
|
|
|
|
|
sub print_f(float value) {
|
|
|
|
; ---- prints the floating point value (without a newline).
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.print_f.value
|
2022-05-04 20:47:48 +02:00
|
|
|
syscall 25
|
2022-04-30 00:10:07 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub pow(float value, float power) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.pow.value
|
|
|
|
loadm.f fr1,floats.pow.power
|
2022-05-11 22:09:46 +02:00
|
|
|
fpow.f fr0,fr1
|
2022-05-01 00:09:03 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub fabs(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.fabs.value
|
2022-05-01 00:09:03 +02:00
|
|
|
fabs.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub sin(float angle) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.sin.angle
|
2022-05-01 00:09:03 +02:00
|
|
|
fsin.f fr0,fr0
|
2022-04-30 00:10:07 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub cos(float angle) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.cos.angle
|
2022-05-01 00:09:03 +02:00
|
|
|
fcos.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub tan(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.tan.value
|
2022-05-01 00:09:03 +02:00
|
|
|
ftan.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub atan(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.atan.value
|
2022-05-01 00:09:03 +02:00
|
|
|
fatan.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ln(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.ln.value
|
2022-05-01 00:09:03 +02:00
|
|
|
fln.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub log2(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.log2.value
|
2022-05-02 20:16:45 +02:00
|
|
|
flog.f fr0,fr0
|
2022-05-01 00:09:03 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub sqrt(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.sqrt.value
|
2022-08-07 17:43:40 +02:00
|
|
|
sqrt.f fr0,fr0
|
2022-05-01 00:09:03 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rad(float angle) -> float {
|
|
|
|
; -- convert degrees to radians (d * pi / 180)
|
2022-05-01 00:09:03 +02:00
|
|
|
return angle * PI / 180.0
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub deg(float angle) -> float {
|
|
|
|
; -- convert radians to degrees (d * (1/ pi * 180))
|
2022-05-01 00:09:03 +02:00
|
|
|
return angle * 180.0 / PI
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub round(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.round.value
|
2022-05-01 00:09:03 +02:00
|
|
|
fround.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub floor(float value) -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.floor.value
|
2022-05-01 00:09:03 +02:00
|
|
|
ffloor.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub ceil(float value) -> float {
|
|
|
|
; -- ceil: tr = int(f); if tr==f -> return else return tr+1
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-09-15 23:08:41 +02:00
|
|
|
loadm.f fr0,floats.ceil.value
|
2022-05-01 00:09:03 +02:00
|
|
|
fceil.f fr0,fr0
|
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub rndf() -> float {
|
2022-09-30 14:05:11 +02:00
|
|
|
%ir {{
|
2022-10-22 17:16:36 +02:00
|
|
|
syscall 35
|
2022-05-01 00:09:03 +02:00
|
|
|
return
|
|
|
|
}}
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|
2022-10-22 13:33:35 +02:00
|
|
|
|
|
|
|
sub rndseedf(ubyte s1, ubyte s2, ubyte s3) {
|
|
|
|
%ir {{
|
|
|
|
loadm.b r0,floats.rndseedf.s1
|
|
|
|
loadm.b r1,floats.rndseedf.s2
|
|
|
|
loadm.b r2,floats.rndseedf.s3
|
|
|
|
syscall 32
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2022-04-23 02:15:51 +02:00
|
|
|
}
|