Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Why does adding 1 to numeric_limits::min() return 1?

$
0
0

How come subtracting 1 from float max returns a sensible value, but adding 1 to float min returns 1?

I thought that if you added or subtracted a value smaller than the epsilon for that particular magnitude, then nothing would happen and there would be no increase or decrease.

Here is the code I compiled with g++ with no flags and ran on x86_64.

#include <limits>#include <iostream>int main() {    float min = std::numeric_limits<float>::min() + 1;    float max = std::numeric_limits<float>::max() - 1;    std::cout << min << std::endl << max << std::endl;    return 0;}

Outputs this:

13.40282e+38

I would expect it to output this:

-3.40282e+38 3.40282e+38

Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>