tsoding / porth

It's like Forth but in Python
629 stars 50 forks source link

Parity error between numbers in simulation and compilation #136

Open Nabushika opened 2 years ago

Nabushika commented 2 years ago

Python uses bigints by default, which means you can have arbitrarily large numbers. I noticed this when writing an abs macro. The following code produces two different outputs on my machine:

include "std.porth"
macro abs
  if dup 0 < do
    0 over - swap drop
  end
end

-18446744073709551615 abs
// becomes 1 on bare metal, 18446744073709551615 in Python
1 - 
if 0 = do
  "We're running on bare metal!\n" puts
else
  "We're in a simulation!\n" puts
end

Not sure if it's worth fixing in Python as when Porth becomes self-hosted this issue will go away. At least it's amusing :)

rexim commented 2 years ago

@Nabushika oh yeah, that's pretty cool! :+1: