[WIP] fix #12884 VM handles float32 correctly for declarations #12906
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT: do not review: marking as
WIP
because of failing tests... tests/stdlib/tjsonmacro.nim in particular seems tricky, maybe this can't be done easilyfixes #12884
see tests/vm/tfloat32.nim
this PR makes VM correctly handle float32 declarations (eg float32 litterals or conversions to float32); eg
1.32'f32
will be 1.320000052452087 instead of 1.32. The internal representation is still float64, but at least the litteral is first cast to the requested type float32. This makes VM code more compatible with RT code when float32 are involved.Caveat: float32 operations (eg a*b) are still calculated using float64 precision instead of float32 precision (see tests/vm/tfloat32.nim), so the VM gives identical results to RT code only when declarations (float32 litterals + explicit float32 conversions) are involved, but results can differ (as before this PR) when float32 operations are involved.
see tests/vm/tfloat32.nim:
runtime value:
echo a2
(1.320000052452087, 1.320000052452087, 1.320000052452087, 1.320000052452087, 1.32, 1.742400169372559, 1.32, 1.32, 1.742400169372559, 2.640000104904175, "float64", "float32")
CT value:
before PR:
echo a1
(1.32, 1.32, 1.32, 1.32, 1.32, 1.7424, 1.32, 1.32, 1.7424, 2.64, "float64", "float32")
after PR:
echo a1
(1.320000052452087, 1.320000052452087, 1.320000052452087, 1.320000052452087, 1.32, 1.742400138473513, 1.32, 1.32, 1.742400138473513, 2.640000104904175, "float64", "float32")