Why is `abs()` implemented differently?Why is “using namespace std” considered bad practice?abs vs std::abs, what does the reference say?What are the differences between a pointer variable and a reference variable in C++?Why can templates only be implemented in the header file?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does changing 0.1f to 0 slow down performance by 10x?Why is it faster to process a sorted array than an unsorted array?opencv compile with clang ok, with gcc not ok os x 10.9Implement divided differences in C++ with variadic templatesBuilding valgrind on OS Xclang run error gcc okC++ regex_search breaks when compiled with -O1

Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?

Is there an application which does HTTP PUT?

No such column 'DeveloperName' on entity 'RecordType' after Summer '19 release on sandbox

What food production methods would allow a metropolis like New York to become self sufficient

How to handle DM constantly stealing everything from sleeping characters?

How to slow yourself down (for playing nice with others)

What was the notion of limit that Newton used?

The meaning of a て-form verb at the end of this sentence

Best species to breed to intelligence

How do I compare the result of "1d20+x, with advantage" to "1d20+y, without advantage", assuming x < y?

How to select certain lines (n, n+4, n+8, n+12...) from the file?

We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?

Why is the Sun made of light elements only?

Why did they go to Dragonstone?

Extending Kan fibrations, without using minimal fibrations

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Why are low spin tetrahedral complexes so rare?

Is ‘despite that’ right?

What's the "magic similar to the Knock spell" referenced in the Dungeon of the Mad Mage adventure?

Why is PerfectForwardSecrecy considered OK, when it has same defects as salt-less password hashing?

Why did Captain America age?

Company threw a surprise party for the CEO, 3 weeks later management says we have to pay for it, do I have to?

Why does increasing the sampling rate make implementing an anti-aliasing filter easier?

Why do Thanos' punches not kill Captain America or at least cause some mortal injuries?



Why is `abs()` implemented differently?


Why is “using namespace std” considered bad practice?abs vs std::abs, what does the reference say?What are the differences between a pointer variable and a reference variable in C++?Why can templates only be implemented in the header file?Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?Why does changing 0.1f to 0 slow down performance by 10x?Why is it faster to process a sorted array than an unsorted array?opencv compile with clang ok, with gcc not ok os x 10.9Implement divided differences in C++ with variadic templatesBuilding valgrind on OS Xclang run error gcc okC++ regex_search breaks when compiled with -O1






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








53















I've had a super frustrating bug in my code for the past few weeks. My code would work exactly as expected on my computer, but as soon as I farmed it out to the HPC server, it would produce weird results.



I've boiled it down to this: on my computer (iMac) the function abs() works with floating point numbers, but on the server abs() truncates it to an integer.



Example:



Server



abs(-1.1341234) = 1


My Mac



abs(-1.1341234) = 1.1341234


Now I know I can fix this by using fabs(), that's not the question. I looked at the versions of gcc on either machine and this is the output:



Server



g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/apps/software/GCCcore/5.4.0/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto --enable-checking=release --disable-multilib --enable-shared=yes --enable-static=yes --enable-threads=posix --enable-gold=default --enable-plugins --enable-ld --with-plugin-ld=ld.gold --prefix=/apps/software/GCCcore/5.4.0 --with-local-prefix=/apps/software/GCCcore/5.4.0 --enable-bootstrap --with-isl=/dev/shm/GCCcore/5.4.0/dummy-/gcc-5.4.0/stage2_stuff
Thread model: posix
gcc version 5.4.0 (GCC)


My Mac



g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin


So my question, why does abs() produce different results between gcc and clang? This issue literally cost me 3 weeks of progress, so as you can imagine I'm a little salty just now...










share|improve this question



















  • 14





    so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

    – Scheff
    Apr 30 at 8:31







  • 3





    @Scheff Oh man, I certainly won't ever forget this lesson...

    – Phill
    Apr 30 at 8:46






  • 5





    @Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

    – Marco13
    Apr 30 at 10:09






  • 1





    related: developers.redhat.com/blog/2016/02/29/…

    – sudo rm -rf slash
    Apr 30 at 14:37






  • 7





    -Wall, fix all warnings. Always.

    – Ben
    Apr 30 at 19:01

















53















I've had a super frustrating bug in my code for the past few weeks. My code would work exactly as expected on my computer, but as soon as I farmed it out to the HPC server, it would produce weird results.



I've boiled it down to this: on my computer (iMac) the function abs() works with floating point numbers, but on the server abs() truncates it to an integer.



Example:



Server



abs(-1.1341234) = 1


My Mac



abs(-1.1341234) = 1.1341234


Now I know I can fix this by using fabs(), that's not the question. I looked at the versions of gcc on either machine and this is the output:



Server



g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/apps/software/GCCcore/5.4.0/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto --enable-checking=release --disable-multilib --enable-shared=yes --enable-static=yes --enable-threads=posix --enable-gold=default --enable-plugins --enable-ld --with-plugin-ld=ld.gold --prefix=/apps/software/GCCcore/5.4.0 --with-local-prefix=/apps/software/GCCcore/5.4.0 --enable-bootstrap --with-isl=/dev/shm/GCCcore/5.4.0/dummy-/gcc-5.4.0/stage2_stuff
Thread model: posix
gcc version 5.4.0 (GCC)


My Mac



g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin


So my question, why does abs() produce different results between gcc and clang? This issue literally cost me 3 weeks of progress, so as you can imagine I'm a little salty just now...










share|improve this question



















  • 14





    so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

    – Scheff
    Apr 30 at 8:31







  • 3





    @Scheff Oh man, I certainly won't ever forget this lesson...

    – Phill
    Apr 30 at 8:46






  • 5





    @Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

    – Marco13
    Apr 30 at 10:09






  • 1





    related: developers.redhat.com/blog/2016/02/29/…

    – sudo rm -rf slash
    Apr 30 at 14:37






  • 7





    -Wall, fix all warnings. Always.

    – Ben
    Apr 30 at 19:01













53












53








53


4






I've had a super frustrating bug in my code for the past few weeks. My code would work exactly as expected on my computer, but as soon as I farmed it out to the HPC server, it would produce weird results.



I've boiled it down to this: on my computer (iMac) the function abs() works with floating point numbers, but on the server abs() truncates it to an integer.



Example:



Server



abs(-1.1341234) = 1


My Mac



abs(-1.1341234) = 1.1341234


Now I know I can fix this by using fabs(), that's not the question. I looked at the versions of gcc on either machine and this is the output:



Server



g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/apps/software/GCCcore/5.4.0/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto --enable-checking=release --disable-multilib --enable-shared=yes --enable-static=yes --enable-threads=posix --enable-gold=default --enable-plugins --enable-ld --with-plugin-ld=ld.gold --prefix=/apps/software/GCCcore/5.4.0 --with-local-prefix=/apps/software/GCCcore/5.4.0 --enable-bootstrap --with-isl=/dev/shm/GCCcore/5.4.0/dummy-/gcc-5.4.0/stage2_stuff
Thread model: posix
gcc version 5.4.0 (GCC)


My Mac



g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin


So my question, why does abs() produce different results between gcc and clang? This issue literally cost me 3 weeks of progress, so as you can imagine I'm a little salty just now...










share|improve this question
















I've had a super frustrating bug in my code for the past few weeks. My code would work exactly as expected on my computer, but as soon as I farmed it out to the HPC server, it would produce weird results.



I've boiled it down to this: on my computer (iMac) the function abs() works with floating point numbers, but on the server abs() truncates it to an integer.



Example:



Server



abs(-1.1341234) = 1


My Mac



abs(-1.1341234) = 1.1341234


Now I know I can fix this by using fabs(), that's not the question. I looked at the versions of gcc on either machine and this is the output:



Server



g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/apps/software/GCCcore/5.4.0/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto --enable-checking=release --disable-multilib --enable-shared=yes --enable-static=yes --enable-threads=posix --enable-gold=default --enable-plugins --enable-ld --with-plugin-ld=ld.gold --prefix=/apps/software/GCCcore/5.4.0 --with-local-prefix=/apps/software/GCCcore/5.4.0 --enable-bootstrap --with-isl=/dev/shm/GCCcore/5.4.0/dummy-/gcc-5.4.0/stage2_stuff
Thread model: posix
gcc version 5.4.0 (GCC)


My Mac



g++ -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin


So my question, why does abs() produce different results between gcc and clang? This issue literally cost me 3 weeks of progress, so as you can imagine I'm a little salty just now...







c++ gcc compilation clang






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 30 at 20:27









Bathsheba

184k27261388




184k27261388










asked Apr 30 at 8:10









PhillPhill

45549




45549







  • 14





    so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

    – Scheff
    Apr 30 at 8:31







  • 3





    @Scheff Oh man, I certainly won't ever forget this lesson...

    – Phill
    Apr 30 at 8:46






  • 5





    @Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

    – Marco13
    Apr 30 at 10:09






  • 1





    related: developers.redhat.com/blog/2016/02/29/…

    – sudo rm -rf slash
    Apr 30 at 14:37






  • 7





    -Wall, fix all warnings. Always.

    – Ben
    Apr 30 at 19:01












  • 14





    so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

    – Scheff
    Apr 30 at 8:31







  • 3





    @Scheff Oh man, I certainly won't ever forget this lesson...

    – Phill
    Apr 30 at 8:46






  • 5





    @Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

    – Marco13
    Apr 30 at 10:09






  • 1





    related: developers.redhat.com/blog/2016/02/29/…

    – sudo rm -rf slash
    Apr 30 at 14:37






  • 7





    -Wall, fix all warnings. Always.

    – Ben
    Apr 30 at 19:01







14




14





so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

– Scheff
Apr 30 at 8:31






so as you can imagine I'm a little salty just now... Annoying but worth the lecture... This will make you very sensitive about these things. ;-) (I don't mean this offensive but rather as a "heads up". Every really annoying bug might at least produce a valuable experience. So, take it positively...)

– Scheff
Apr 30 at 8:31





3




3





@Scheff Oh man, I certainly won't ever forget this lesson...

– Phill
Apr 30 at 8:46





@Scheff Oh man, I certainly won't ever forget this lesson...

– Phill
Apr 30 at 8:46




5




5





@Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

– Marco13
Apr 30 at 10:09





@Scheff No. A good programming language should not have such quirks. (There's still a lesson to be learned here, but I won't tell which one ;-) )

– Marco13
Apr 30 at 10:09




1




1





related: developers.redhat.com/blog/2016/02/29/…

– sudo rm -rf slash
Apr 30 at 14:37





related: developers.redhat.com/blog/2016/02/29/…

– sudo rm -rf slash
Apr 30 at 14:37




7




7





-Wall, fix all warnings. Always.

– Ben
Apr 30 at 19:01





-Wall, fix all warnings. Always.

– Ben
Apr 30 at 19:01












1 Answer
1






active

oldest

votes


















83














You must use std::abs, which has overloads for the primitive types.



You are falling through to the C++ version in one case, and the old C version (which converts its parameters to integral types) in the other.



Things to avoid: (1) using namespace std; (here is why) and (2) not having the appropriate #includes to bring in the functionality you need. Don't rely on C++ standard library implementations to include files for you implicitly.



Some compilers will warn you of a "lossy" conversion if you set the warning level appropriately.






share|improve this answer




















  • 34





    @BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

    – Bathsheba
    Apr 30 at 9:24






  • 6





    @BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

    – Kami Kaze
    Apr 30 at 12:54






  • 1





    Correction: Use fabs instead of abs OR std::abs which is a template function.

    – mid
    Apr 30 at 17:30







  • 8





    All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

    – Cody Gray
    May 1 at 2:29






  • 2





    @Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

    – Bathsheba
    May 1 at 12:44











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55916514%2fwhy-is-abs-implemented-differently%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









83














You must use std::abs, which has overloads for the primitive types.



You are falling through to the C++ version in one case, and the old C version (which converts its parameters to integral types) in the other.



Things to avoid: (1) using namespace std; (here is why) and (2) not having the appropriate #includes to bring in the functionality you need. Don't rely on C++ standard library implementations to include files for you implicitly.



Some compilers will warn you of a "lossy" conversion if you set the warning level appropriately.






share|improve this answer




















  • 34





    @BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

    – Bathsheba
    Apr 30 at 9:24






  • 6





    @BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

    – Kami Kaze
    Apr 30 at 12:54






  • 1





    Correction: Use fabs instead of abs OR std::abs which is a template function.

    – mid
    Apr 30 at 17:30







  • 8





    All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

    – Cody Gray
    May 1 at 2:29






  • 2





    @Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

    – Bathsheba
    May 1 at 12:44















83














You must use std::abs, which has overloads for the primitive types.



You are falling through to the C++ version in one case, and the old C version (which converts its parameters to integral types) in the other.



Things to avoid: (1) using namespace std; (here is why) and (2) not having the appropriate #includes to bring in the functionality you need. Don't rely on C++ standard library implementations to include files for you implicitly.



Some compilers will warn you of a "lossy" conversion if you set the warning level appropriately.






share|improve this answer




















  • 34





    @BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

    – Bathsheba
    Apr 30 at 9:24






  • 6





    @BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

    – Kami Kaze
    Apr 30 at 12:54






  • 1





    Correction: Use fabs instead of abs OR std::abs which is a template function.

    – mid
    Apr 30 at 17:30







  • 8





    All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

    – Cody Gray
    May 1 at 2:29






  • 2





    @Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

    – Bathsheba
    May 1 at 12:44













83












83








83







You must use std::abs, which has overloads for the primitive types.



You are falling through to the C++ version in one case, and the old C version (which converts its parameters to integral types) in the other.



Things to avoid: (1) using namespace std; (here is why) and (2) not having the appropriate #includes to bring in the functionality you need. Don't rely on C++ standard library implementations to include files for you implicitly.



Some compilers will warn you of a "lossy" conversion if you set the warning level appropriately.






share|improve this answer















You must use std::abs, which has overloads for the primitive types.



You are falling through to the C++ version in one case, and the old C version (which converts its parameters to integral types) in the other.



Things to avoid: (1) using namespace std; (here is why) and (2) not having the appropriate #includes to bring in the functionality you need. Don't rely on C++ standard library implementations to include files for you implicitly.



Some compilers will warn you of a "lossy" conversion if you set the warning level appropriately.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 30 at 9:07

























answered Apr 30 at 8:14









BathshebaBathsheba

184k27261388




184k27261388







  • 34





    @BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

    – Bathsheba
    Apr 30 at 9:24






  • 6





    @BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

    – Kami Kaze
    Apr 30 at 12:54






  • 1





    Correction: Use fabs instead of abs OR std::abs which is a template function.

    – mid
    Apr 30 at 17:30







  • 8





    All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

    – Cody Gray
    May 1 at 2:29






  • 2





    @Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

    – Bathsheba
    May 1 at 12:44












  • 34





    @BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

    – Bathsheba
    Apr 30 at 9:24






  • 6





    @BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

    – Kami Kaze
    Apr 30 at 12:54






  • 1





    Correction: Use fabs instead of abs OR std::abs which is a template function.

    – mid
    Apr 30 at 17:30







  • 8





    All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

    – Cody Gray
    May 1 at 2:29






  • 2





    @Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

    – Bathsheba
    May 1 at 12:44







34




34





@BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

– Bathsheba
Apr 30 at 9:24





@BenjaminBihler: That kicks the can down the road - fabs breaks for long double for example.

– Bathsheba
Apr 30 at 9:24




6




6





@BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

– Kami Kaze
Apr 30 at 12:54





@BenjaminBihler if you are using c++ there is normally no good reason not to use the c++ version of the functions. Keep C to C and C++ to C++.

– Kami Kaze
Apr 30 at 12:54




1




1





Correction: Use fabs instead of abs OR std::abs which is a template function.

– mid
Apr 30 at 17:30






Correction: Use fabs instead of abs OR std::abs which is a template function.

– mid
Apr 30 at 17:30





8




8





All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

– Cody Gray
May 1 at 2:29





All compilers should warn you of a floating-point to integer, or integer to floating-point, conversion. If your compiler doesn't, and you can't adjust its warning levels accordingly, discard it immediately and get yourself a better compiler.

– Cody Gray
May 1 at 2:29




2




2





@Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

– Bathsheba
May 1 at 12:44





@Rakete1111: It's lossy in full generality. E.g. 64 bit int, and IEEE754 double.

– Bathsheba
May 1 at 12:44



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55916514%2fwhy-is-abs-implemented-differently%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020