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

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company