Fixed-point values can use all 32-Q magnitude bits (#1085)

This commit is contained in:
Rangi
2022-10-02 05:08:38 -04:00
committed by GitHub
parent ab12c474d2
commit 8553b61a94
4 changed files with 294 additions and 28 deletions

View File

@@ -1,13 +1,19 @@
OPT Q.4
println 1.0
println -1.0
println 0.0625
println -0.0625
println 7.25
println -7.25
println 12.25
println -12.25
println 15.9375
println -15.9375
println 20.0
println -20.0
for precision, 1, 32
opt Q{d:precision}
def magnitude = 32 - precision
def maxInt = 1 << magnitude - 1
redef defMaxValue equs "def maxValue = {d:maxInt}.0"
{defMaxValue}
println "Q.{2d:precision}: max ok = 1 << {2d:magnitude} - 1 = {11d:maxInt}.0 = {#09x:maxValue}"
def minBadInt = maxInt + 1
redef defMinBadValue equs "def minBadValue = {d:minBadInt}.0"
{defMinBadValue}
println "Q.{2d:precision}: min bad = 1 << {2d:magnitude} = {11d:minBadInt}.0 = {#09x:minBadValue}"
def worseInt = minBadInt + 42
redef defWorseValue equs "def worseValue = {d:worseInt}.0"
{defWorseValue}
println "Q.{2d:precision}: worse = 1 << {2d:magnitude} + 42 = {11d:worseInt}.0 = {#09x:worseValue}"
endr