-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Prevent abs() macro from sign-flipping 0.0F #8116
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
base: master
Are you sure you want to change the base?
Conversation
This variant solves the
|
In the original PR in the AVR, I fail to see the actual bug they're solving. If Since this is a macro (thanks, Arduino) it seems like it will add 32 bytes per call, everywhere, with the change, which seems large. |
@earlephilhower Within a single compilation unit, the compiler seems to optimize that overhead. But as you can tell from me not putting it into the PR, instead just giving it a showing in a remark, I don't see much need for that myself. As for this PR, I find some merit in having all-zero bits representation at least for the positive zero, such that (uint32_t)0 and (float)0 are the same in memory. For what it's worth :-) |
There's also another approach - just use compiler built-ins to implement overloading, as floats also include things like Not sure of code generation though, but it seems more of actually solving the issue instead of working around a certain part. |
@mcspr This is not as much about a more perfect abs() function, as it is about being Arduino-alike. |
then, I'd agree with the comment above - no point in fixing anything, as neither abs or round macros are provided in the current ArduinoCore API headers in favour of math.h: and current macro can stay as-is, until the issue above is definitely closed and there's a clear answer what arduino side want to do with them |
3c084a7
to
13e62b8
Compare
Fixes #8115