point underflow in program output
I have done a thorough search but only seem to find explanations of what underflow is, and how it works, rather than ways to represent it.
Long story short, I'm writing a program to experiment with integer overflow, floating-point overflow (inf) and underflow -- and outputting the effects of these conditions using the printf function. I've been successful with the first two, but can't seem to successfully represent a subnormal number as a result of floating-point underflow. To my knowledge, I know that, depending on how the system handles the condition, a symptom of underflow could be a loss of a digit in the output, or a rounding-off to zero.
In an attempt to find the lowest floating-point values, I looked at the float.h header file. FLT_MIN comes up as 0.000000 (thus unworkable in demonstrating an operation that leads to underflow), and DEC32_MIN (which I believe holds the smallest possible normalized positive value) keeps being flagged by the compiler as 'undefined' despite the float.h header file being included, which is rather unnerving. After which, I searched for the smallest possible normalized non-zero 32-bit floating-point value on the internet, experimented with dividing them in all manner of ways; and yet my system still seems to represent it in the same format, seemingly completely avoiding an underflow.
I know it seems rather far-fetched that I'm asking to deliberately cause an error and represent it accurately, but it is for educational purposes.
My system handles floats as 32 bits, doubles as 64 bits and long doubles as 128 bits. May as well mention that.
The question is; how can I create an underflow with float, double and long double types and represent it in the output so it is visibly an underflow error?
Alongside an answer, any help in regards to explaining floating-point underflow further would be very much appreciated. I am rather new to C and programming as a whole.
Thank you,
GS
链接地址: http://www.djcxy.com/p/90306.html上一篇: 对于存储为union的数据,printf在调用double变量后不会输出
下一篇: 在程序输出中出现下溢