Repository navigation
Print a C++ float joined to a String as the Float of its value prints - #488
Open
dimensionscape wants to merge 1 commit into
Open
dimensionscape wants to merge 1 commit into
dimensionscape wants to merge 1 commit into
Conversation
String's constructor from a float had its own copy of the formatting, and it stayed "%.15g" when a Float got the shortest digits that read back. So native code printed "" + bytes.getFloat(0) as 0.333333343267441, and the same value held in a Float first as 0.3333333432674408, which is what cppia and the other targets print for both. Lime's Matrix3.toString showed it in any native build. The float constructor now makes its String from the double of the same value, so it takes the shortest digits, or the format a program set, exactly as a Float does.
dimensionscape
force-pushed
the
fix/string-float-digits
branch
from
November 26, 2026 16:41
c99d847 to
cc0f63b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #486.
Native code printed a 32-bit float joined straight to a
Stringwith 15 significant digits, and the same value held in aFloatfirst with the shortest digits that read back:cppia and Haxe's interpreter print
0.3333333432674408for both. Small exponents differed too:1.0000000116861e-07against1.0000000116860974e-7.Cause and change
String::String(const float &)had its own copy of the formatting, and it stayed%.15gwhenString::String(const double &)got the shortest digits. It now makes itsStringfrom the double of the same value, so a float takes the shortest digits, or the format a program set with__hxcpp_set_float_format, exactly as aFloatdoes.This changes what native programs print for such a float: more digits where 15 did not read back. Lime's
Matrix3.toStringis one place it shows.Tests
test/regression/FloatFromSingleprints each value joined straight from the read and from aFloatvariable, and the two lines of each pair must be the same: fractions, a small exponent, the largest float, the smallest denormal, zeros, infinities, NaN, and a set format. Before the change 5 of its 28 lines differed.None of the existing tests prints a 32-bit read through this constructor, so no existing
stdout.txtchanges.Run on 64-bit Windows with MSVC and Haxe 4.3.7:
FloatFromSingle,FloatFormatPattern,FloatShortestDigits,BytesOddOffsets,CppiaFloat32Array,CppiaJitBuiltins,CppiaFloatFrames,BoxNegativeZero,DynamicDoubleRange,EnumFormattingShapes,MapFormattingCycles,ParseFloatWords, andtest/haxe(2698 assertions). Those ran before the branch was rebased onto the commit that opens 6.0.1, which changes only the version andChanges.md;FloatFromSingleandFloatShortestDigitsran again after it.Not run here: the whole of
test/regression,test/std, and the other platforms.The
Changes.mdentry sits at the same place as the one in the pull request for #485, so whichever merges second needs a rebase.