-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VM: float32 values incorrect, resulting in differences between RT and CT #12884
Comments
That's because in the VM everything is a float64. Now, we don't lose precision here and I think float32 in the VM would be extra maintenance with few use cases when we already have float64. My take is to add this as an exception to the specs. "As an exception to VM and constant folding computations being equal to runtime computations, all floating point operations are carried with 64-bit precision at compile-time." |
the final representation is up-casted to float64 but the intermediate one should be whatever user asked for, ie float32 in case above; float64 can represent all float32 values so these values should be preserved on a related note,
probably due to same issue; I consider it a bug proc main()=
let x = float(1.32'f32)
echo x
echo 1.32
echo 1.32'f32
let x2 = 1.32'f32
echo x2
main() output:
|
The C spec also says that floating point compile time evaluations can have higher precision. It's just an inherit complexity in compilers, it needs to be documented, it is not a bug. |
#12906 mitigates this; after this PR operations (eg multiplications) can be computed using higher precision, but declarations (eg float32 litterals) and float32 conversions shall use the user requested precision to match RT code |
In fact, the spec already says that:
So ... closing. |
VM code should as much as possible produce identical results as runtime code; but that's not the case for float32:
Example1
Current Output
Expected Output
Example2
this shows that there's a discrepency in VM between float32's from FFI and float32 from litterals:
get_float returns
1.320000052452087
(as it should) which does not match the incorrect 1.32 from 1.32'f32prints:
Additional Information
recent devel 7213969
The text was updated successfully, but these errors were encountered: