-
-
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
Fix strformat neg zero #7954
Fix strformat neg zero #7954
Conversation
lib/pure/strformat.nim
Outdated
if value == 0.0: | ||
if 1.0 / value == Inf: | ||
# only add the sign if value != negZero | ||
f = spec.sign & f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use insert
instead, to modify 'f' in place? It would be nice to reduce the number of temporary string allocations made in this procedure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other places where we could use insert
instead of string concatenation, but i limit the change strictly to the area i want to fix (no +
in front of negative zero).
Personally i don't like inplace mutations, therefore I will not produce PR's to change other places in strformat to use inplace mutations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter if you like them or not, they are faster and this is a "standard library" where everybody benefits from faster code.
only add explicitly requested sign if value != -0.0 (neg zero)
see issue #7923