mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 07:31:48 +00:00
added several float limits contants such as floats.EPSILON, E, MIN, MAX
fix VM float min max limits
This commit is contained in:
parent
844c97930f
commit
8badc40883
@ -10,8 +10,8 @@ class VirtualMachineDefinition: IMachineDefinition {
|
||||
|
||||
override val cpu = CpuType.VIRTUAL
|
||||
|
||||
override val FLOAT_MAX_POSITIVE = Float.MAX_VALUE.toDouble()
|
||||
override val FLOAT_MAX_NEGATIVE = -Float.MAX_VALUE.toDouble()
|
||||
override val FLOAT_MAX_POSITIVE = Double.MAX_VALUE.toDouble()
|
||||
override val FLOAT_MAX_NEGATIVE = -Double.MAX_VALUE.toDouble()
|
||||
override val FLOAT_MEM_SIZE = 8 // 64-bits double
|
||||
override val STARTUP_CODE_RESERVED_SIZE = 0u // not actually used
|
||||
override val PROGRAM_LOAD_ADDRESS = 0u // not actually used
|
||||
|
@ -2,9 +2,14 @@ floats {
|
||||
; the floating point functions shared across compiler targets
|
||||
%option merge, no_symbol_prefixing, ignore_unused
|
||||
|
||||
const float π = 3.141592653589793
|
||||
const float PI = π
|
||||
const float TWOPI = 2*π
|
||||
const float π = 3.141592653589793
|
||||
const float PI = π
|
||||
const float TWOPI = 2*π
|
||||
const float E = 2.718281828459045
|
||||
const float EPSILON = 2.938735878e-39 ; bytes: 1,0,0,0,0
|
||||
const float MAX_FLOAT = 1.7014118345e+38 ; bytes: 255,127,255,255,255
|
||||
const float MIN_FLOAT = -1.7014118345e+38 ; bytes: 255,255,255,255,255
|
||||
const ubyte SIZEOF = 5
|
||||
|
||||
|
||||
asmsub print(float value @FAC1) clobbers(A,X,Y) {
|
||||
|
@ -4,9 +4,14 @@
|
||||
|
||||
floats {
|
||||
|
||||
const float π = 3.141592653589793
|
||||
const float PI = π
|
||||
const float TWOPI = 2*π
|
||||
const float π = 3.141592653589793
|
||||
const float PI = π
|
||||
const float TWOPI = 2*π
|
||||
const float E = 2.718281828459045
|
||||
const float EPSILON = 4.9E-324
|
||||
const float MAX_FLOAT = 1.7976931348623157e+308
|
||||
const float MIN_FLOAT = -1.7976931348623157e+308
|
||||
const ubyte SIZEOF = 8
|
||||
|
||||
|
||||
sub print(float value) {
|
||||
|
@ -1830,8 +1830,8 @@ internal class AstChecker(private val program: Program,
|
||||
when (targetDt) {
|
||||
DataType.FLOAT -> {
|
||||
val number=value.number
|
||||
if (number > 1.7014118345e+38 || number < -1.7014118345e+38)
|
||||
return err("value '$number' out of range for MFLPT format")
|
||||
if (number > compilerOptions.compTarget.machine.FLOAT_MAX_POSITIVE || number < compilerOptions.compTarget.machine.FLOAT_MAX_NEGATIVE)
|
||||
return err("value '$number' out of range")
|
||||
}
|
||||
DataType.UBYTE -> {
|
||||
if(value.type==DataType.FLOAT)
|
||||
|
@ -1,8 +1,19 @@
|
||||
%import floats
|
||||
%import textio
|
||||
%option no_sysinit
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
cx16.r0s = if cx16.r0L < cx16.r1L -1 else 1
|
||||
floats.print(floats.EPSILON)
|
||||
txt.nl()
|
||||
floats.print(floats.MIN_FLOAT)
|
||||
txt.nl()
|
||||
floats.print(floats.MAX_FLOAT)
|
||||
txt.nl()
|
||||
floats.print(floats.E)
|
||||
txt.nl()
|
||||
txt.print_ub(floats.SIZEOF)
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user