3 ms·
Looks like more code here for abs.c https://bitbucket.org/pdclib/pdclib/src/95be959efe2ed2f36104ab5cffe9c222972d3e43/functions/stdlib/abs.c?at=default&fileview
by kchauhan 10y ago
Looks like more code here for abs.c
https://bitbucket.org/pdclib/pdclib/src/95be959efe2ed2f36104ab5cffe9c222972d3e43/functions/stdlib/abs.c?at=default&fileviewer=file-view-default https://bitbucket.org/pdclib/pdclib/src/95be959efe2ed2f36104...
than musl:
https://git.musl-libc.org/cgit/musl/tree/src/stdlib/abs.c https://git.musl-libc.org/cgit/musl/tree/src/stdlib/abs.c
- anilgulecha 10y agoBecause it includes testcases.
- therein 10y agoYou'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.