473,413 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Negative infinity

Hello all,

I'd like to get the negative value of largest possible magnitude for a
float. I've considered:

-numeric_limits<float>::max()

and

-numeric_limits<float>::infinity()

Are either of these correct? If not, how may I accomplish my goal?

Thanks,
Dave

May 4 '06 #1
8 12288

be***********@yahoo.com wrote:
Hello all,

I'd like to get the negative value of largest possible magnitude for a
float. I've considered:

-numeric_limits<float>::max()

and

-numeric_limits<float>::infinity()

Are either of these correct? If not, how may I accomplish my goal?


Seems like min() would do it and be more meaningful.

May 4 '06 #2
Unfortunately, min() returns the positive value of smallest magnitude,
not the negative value of largest magnitude (which is what I want).

May 4 '06 #3

be***********@yahoo.com wrote:
Unfortunately, min() returns the positive value of smallest magnitude,
not the negative value of largest magnitude (which is what I want).


Eek, so it does.

max() is probably better then because it will work so long as
is_bounded != false and I think this more likely than has_infinity !=
false. Can't think of a case when either is false but there appears to
be less restrictions on max() so use it.

May 4 '06 #4

Noah Roberts wrote:
be***********@yahoo.com wrote:
Unfortunately, min() returns the positive value of smallest magnitude,
not the negative value of largest magnitude (which is what I want).


Eek, so it does.

max() is probably better then because it will work so long as
is_bounded != false and I think this more likely than has_infinity !=
false. Can't think of a case when either is false but there appears to
be less restrictions on max() so use it.


Hmmm, this takes us back to the original question of whether the
following is well-formed code according to the C++ Standard:

float num := -numeric_limits<float>::max(); // Note the minus sign

Is the value I'm trying to assign to num above always representable and
legal on a standards-conforming compiler?

May 4 '06 #5
be***********@yahoo.com wrote:
float num := -numeric_limits<float>::max(); // Note the minus sign

Is the value I'm trying to assign to num above always representable and
legal on a standards-conforming compiler?

Since C and C++ try to use the native floating-point format, this is
a question about how silly a hardware implementation might be. max
would be valid but not the right answer on Multics, which used a
twos-complement representation of the mantissa, so there is "one more"
negative value than positive. This gives other silly effects such as
an exponent overflow on negate or abs.
May 4 '06 #6

Robert Mabee wrote:
be***********@yahoo.com wrote:
float num := -numeric_limits<float>::max(); // Note the minus sign

Is the value I'm trying to assign to num above always representable and
legal on a standards-conforming compiler?

Since C and C++ try to use the native floating-point format, this is
a question about how silly a hardware implementation might be. max
would be valid but not the right answer on Multics, which used a
twos-complement representation of the mantissa, so there is "one more"
negative value than positive. This gives other silly effects such as
an exponent overflow on negate or abs.


OK, so it sounds like it's platform-dependent and not mandated by the
standard.

May 4 '06 #7
On Thu, 04 May 2006 16:17:45 -0700, be***********@yahoo.com wrote:

Robert Mabee wrote:
be***********@yahoo.com wrote:
> float num := -numeric_limits<float>::max(); // Note the minus sign
>
> Is the value I'm trying to assign to num above always representable
> and legal on a standards-conforming compiler?
>

Since C and C++ try to use the native floating-point format, this is a
question about how silly a hardware implementation might be. max would
be valid but not the right answer on Multics, which used a
twos-complement representation of the mantissa, so there is "one more"
negative value than positive. This gives other silly effects such as an
exponent overflow on negate or abs.


OK, so it sounds like it's platform-dependent and not mandated by the
standard.


Is what platform dependent, the value of num or the method of calculating
it? Certainly num is platform dependent, but whether or not the method of
calculating it is...I'm not sure.

If you understand the ieee floating point formats better than I you might
be able to bit pack contiguous bytes of memory to the size of a float and
then cast that memory space as a float to see what dribbles out.

May 5 '06 #8
noone wrote:
If you understand the ieee floating point formats better than I you might
be able to bit pack contiguous bytes of memory to the size of a float and
then cast that memory space as a float to see what dribbles out.


If you've got hardware modern enough to have IEEE floating point then
-max IS the minimum (negative infinity). The problem is to write code
that is portable to an unspecified set of architectures, maybe including
some with surprising "features". Perhaps OP would be better served by
specifying his program is only portable to "reasonable" machines, such
as only those on which -max is a valid extremely-negative number.
May 6 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. Is there anything like +infinity and -infinity available in Python, and can it be used in comparisons together with int or float numbers? Regards Andreas
2
by: Russell Smith | last post by:
Timestamps support infinity. However if appears dates do not. When timestamps are cast to dates, there is no output. Is this an acceptable option or not? Below are a number of examples...
5
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that special float values are a "platform-dependent...
2
by: Pierre Rouleau | last post by:
Hi all, When using Python 2.4.x on a Win32 box, marshal.loads(marshal.dumps(1e66666)) returns 1.0 instead of infinity as it should and does under Python 2.5 (also running on Win32 ). This...
7
by: intrader | last post by:
The regular expression is /(?!((00000)|(11111)))/ in oRe. That is oRE=/(?!((00000)|(11111)))/ The test strings are 92708, 00000, 11111 in checkStr The expression used is checkStr.search(oRE). The...
12
by: horacius.rex | last post by:
Hi, I have a code that in some part of the program calculates 1/x for a lot of different x's. About 1 of 100 times x is equal to zero, so when I print the result I obtain inf. I wonder if there...
5
by: westhood | last post by:
In my program I must have some variables which values are infinity. It means the variable must be bigger than any integer. And if we add some to it, its value should still be infinity. I try...
14
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
13
by: kimiraikkonen | last post by:
Hello, I have an aritmetic calculation like this: First note that: i need a "timer" to get the value for value3. (however removing "timer" didn't differ) Dim value1 As Long Dim value2 As...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.