By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,128 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,128 IT Pros & Developers. It's quick & easy.

minimum float value

P: n/a
I have a float value which should be initialized to the minimum allowed
value (analogous to -infinity). I discovered today (thank you, unit
tests!) that numeric_limits<float>::min() returns a very small number
greater than 0, rather than the extremely negative number which I want.
Is it safe to use -numeric_limits<float>::max() for this purpose, or
is something else preferred?
Thanks,
Mark
Dec 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Mark P wrote:
I have a float value which should be initialized to the minimum allowed
value (analogous to -infinity).
What about actually using -infinity?

float init = numeric_limits<float>::has_infinity
? -numeric_limits<float>::infinity()
: -numeric_limits<float>::max();
I discovered today (thank you, unit
tests!) that numeric_limits<float>::min() returns a very small number
greater than 0, rather than the extremely negative number which I want.
Is it safe to use -numeric_limits<float>::max() for this purpose
In general? I suppose no. In practice, if your "float" represents
an IEEE754/854 number (a very common floating point standard), then you
should be safe, since a sign bit stored separately (no two's
complement).

Greg Buchholz

Dec 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.