473,830 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>::infinit y()

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

Thanks,
Dave

May 4 '06 #1
8 12315

be***********@y ahoo.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>::infinit y()

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***********@y ahoo.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***********@y ahoo.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***********@y ahoo.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***********@y ahoo.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***********@y ahoo.com wrote:

Robert Mabee wrote:
be***********@y ahoo.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
68764
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
4378
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 showing what I am experiencing. The last own shows how converting timestamps to dates and then ordering doesn't give you the order you want. Maybe you should just order by the timestamp to begin with. However Date does not understand infinity at all.
5
4202
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 accident" etc...) The issue appears possibly to point to a bug in the Python compiler, with it producing inconsistent results. I'm using "Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32". This code sometimes produces a float of 1.0, sometimes...
2
1924
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 problem was reported in another thread here by Peter Hansen http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/5c2b4b2a88c8df4/f216739705c9304f?lnk=gst&q=simplejson&rnum=5#f216739705c9304f Is this considered an important enough...
7
3152
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 values returned are are 0,1,1 - the values should be 0,-1,-1. The positive lookahead expressiono RE=/(?=((00000)|(11111)))/ returns -1, 0, 0 respectively - this is correct
12
2575
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 is a way to detect this "infinity" and convert it to the float zero. I mean something like for i = .... calculate 1/x_i
5
9807
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 to use the max value of int ,but it will cause overflow if you add something to it. I also try to write a class INF,in which I overload operator + and >. But those variables sometimes should be integer,i can not make them be the in instances of...
14
5558
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
2325
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 String Dim value3 As String value3 = (value2 * 8) / value1
0
9790
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10770
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10481
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10199
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6948
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5616
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3074
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.