This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: -O generates NaN


Hello,

From: Michael Meissner <meissner@cygnus.com>
Subject: Re: -O generates NaN
Date: Mon, 5 Mar 2001 09:02:58 -0500
Message-ID: <20010305090258.A10882@cse.cygnus.com>

> On Sat, Mar 03, 2001 at 02:26:57PM +0900, Haruhiko Okumura wrote:
> > The problem looks like a gcc bug.  The attached shorter program,
> > nan3.cc, also generates NaN's only when compiled with -O.
> 
> It looks like the attachment did not survive the mailing.  Could you resend it?

Here it is:

----------------------------------------------------------------------
// nan3.cc
// g++ -O nan3.cc generates NaN.
// g++ nan3.cc is OK.
// Haruhiko Okumura <okumura@matsusaka-u.ac.jp>

#include <iostream>
#include <cmath>

using namespace std;

const double pi = 3.14159265358979323846;

const double conductor_radius = 0.0001265;
const double wire_radius = 0.0001725;
const double bobbin_radius = 0.183;
const double solenoid_length = 0.1;
const double turns = 74.5;
const int STEPRAD = 100;
const double solenoid_pitch = solenoid_length / (turns + 1);
const double thetamax = 2 * turns * pi;
const int IMAX = int(STEPRAD * thetamax) + 1;

double xx[2][IMAX+1], yy[2][IMAX+1], zz[2][IMAX+1];

void wind0()
{
    double rmin, rmax, r, zmin, zmax, z;

    rmin = bobbin_radius + wire_radius;
    rmax = bobbin_radius + solenoid_pitch - wire_radius;
    zmin = wire_radius;
    zmax = solenoid_pitch - wire_radius;
    r = (rmin + rmax) / 2;
    z = (zmin + zmax) / 2;
    for (int i = 0; i <= IMAX; i++) {
        double theta = double(i) / STEPRAD;
        xx[0][i] = r * cos(theta);
        yy[0][i] = r * sin(theta);
        zz[0][i] = z + solenoid_pitch * theta / (2 * pi);
    }
    rmin = bobbin_radius + solenoid_pitch + wire_radius;
    rmax = bobbin_radius + 2 * solenoid_pitch - wire_radius;
    zmin = wire_radius;
    zmax = solenoid_pitch - wire_radius;
    r = (rmin + rmax) / 2;
    z = (zmin + zmax) / 2;
    for (int i = 0; i <= IMAX; i++) {
        double theta = double(i) / STEPRAD;
        xx[1][i] = r * cos(theta);
        yy[1][i] = r * sin(theta);
        zz[1][i] = solenoid_length - solenoid_pitch + z - solenoid_pitch * theta / (2 * pi);
    }
}

int main()
{
    wind0();
    for (int i = 0; i < 5; i++)
        cout << i << "..." << zz[1][i] << endl;
}
----------------------------------------------------------------------

-- 
Haruhiko Okumura <okumura@matsusaka-u.ac.jp>
Matsusaka University, 1846 Kubo-cho, Matsusaka, 515-8511 Japan
Phone: +81-598-29-1122  Fax: +81-598-29-1014
http://www.matsusaka-u.ac.jp/~okumura/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]