Log In  

What is the method to introspect on exact floating point values with pico8's fixed point system?

x = 3.8
y = 6.8
x += 0.2
y += 0.2
rectfill(x*15,y*9,x*15+1,y*9+1,9)
rectfill(4*15,7*9,4*15+1,7*9+1,12)
print(x)
print(y)

Running this produces two squares that do not overlap, although print() of x or y shows that the value is equivalent to an integer. Is there a way to print the fractional section more accurately?

P#18478 2016-01-26 14:41 ( Edited 2016-01-27 00:44)

There isn't a built-in hex printer, but binary operations shl() and band() can be used to grab each nibble:

cls()

function print_hex(n)
  local c="0123456789abcdef"
  local s="0x"
  for i=7,0,-1 do
    local v = band(shr(n,i*4),0x.000f)
    v = shl(v,16)
    s=s..sub(c,v+1,v+1)
  end
  return(s)
end

a=0xdead.beef
print(print_hex(a))
a=a+0x.0001
print(print_hex(a))
a = 3.8
print(print_hex(a)) -- 0x0003cccc
a += 0.2
print(print_hex(a)) -- 0x0003ffff
P#18481 2016-01-26 19:44 ( Edited 2016-01-27 00:51)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 06:36:26 | 0.005s | Q:9