3 ms·
You're absolutely 100% correct but to play the devil's advocate, what if he is talking about it being glibc: > return ( j >= 0 ) ? j : -j; Musl: > return a>
by therein 10y ago
You're absolutely 100% correct but to play the devil's advocate, what if he is talking about it being
glibc:
> return ( j >= 0 ) ? j : -j;
Musl:
> return a>0 ? a : -a;
- reidrac 10y agoIt really doesn't matter, the compiler will generate the same code (gcc -S at least does generate the same assembler output for both pieces of code; see: https://gist.github.com/reidrac/afb89b29228a243954bd51281c39ee88 https://gist.github.com/reidrac/afb89b29228a243954bd51281c39...). I guess looking at the definition: https://en.wikipedia.org/wiki/Absolute_value#Real_numbers https://en.wikipedia.org/wiki/Absolute_value#Real_numbers I would say `( j >= 0 ) ? j : -j` is more accurate, although in practical terms is the same result.