Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: INFINITY and -pedantic with gcc



You could instead use <limits> and the numeric_limits class. Just a quick example:

#include <limits>
#include <cmath>
#include <iostream>

using namespace std;

int main (int argc, char** argv)
{
    double inf1 = numeric_limits<double>::infinity();
    cout << "Infinity: " << inf1 << endl;

    /*
    double inf2 = INFINITY;
    cout << "Infinity: " << inf2 << endl;
    if (inf1 == inf2)
        cout << "They're equal." << endl;
    */

    return 0;
}


Un-comment the code involving INFINITY, and it won't compile with - pedantic, but you'll see that they're equivalent. The above code, will however compile with -pedantic. I think this is the better way to do it as well, but that could just be me.


-matt

On Aug 3, 2005, at 11:59 AM, Jasmin Lapalme wrote:

Hi,
I have curious bug with gcc and the option -pedantic.
I want to use the value INFINITY defined in math.h. Here is a sample code :
==== test.cpp ====
#include <cmath>
#include <iostream>


using namespace std;

void test_inf(double &x) {
  x = INFINITY;
}

int main() {
  double x;
  test_inf(x);
  cout << x << endl;
}
===========

This code compiles well without the option -pedantic but I want to use the option -pedantic. I want to be sure my code will compile on any platform with gcc. I know that INFINITY is equal to 1e50f and 1e50f is greater than FLT_MAX. The option -pedantic raise this error : floating constant exceeds range of 'float'.
Why I cannot use INFINITY with the option -pedantic?


Thanks

Jasmin




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/mhoffman% 40cs.washington.edu


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden
References: 
 >INFINITY and -pedantic with gcc (From: Jasmin Lapalme <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.