Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

c - Why is FLT_MIN equal to zero?

limits.h specifies limits for non-floating point math types, e.g. INT_MIN and INT_MAX. These values are the most negative and most positive values that you can represent using an int.

In float.h, there are definitions for FLT_MIN and FLT_MAX. If you do the following:

NSLog(@"%f %f", FLT_MIN, FLT_MAX);

You get the following output:

FLT_MIN = 0.000000, FLT_MAX = 340282346638528859811704183484516925440.000000

FLT_MAX is equal to a really large number, as you would expect, but why does FLT_MIN equal zero instead of a really large negative number?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's not actually zero, but it might look like zero if you inspect it using printf or NSLog by using %f.
According to float.h (at least in Mac OS X 10.6.2), FLT_MIN is described as:

/* Minimum normalized positive floating-point number, b**(emin - 1).  */

Note the positive in that sentence: FLT_MIN refers to the minimum (normalized) number greater than zero. (There are much smaller non-normalized numbers).

If you want the minimum floating point number (including negative numbers), use -FLT_MAX.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...