GCC Reports Errors With C++ Using Math.h Functions (3.1.8)

1,043 views
Skip to first unread message

pikpik

unread,
Oct 29, 2010, 4:09:50 PM10/29/10
to minix3
Hi,

In MINIX 3.1.8, using GCC 4.4.3, I tried to compile the following C++
file and received errors.

Contents of "math.cpp":

#include <iostream>
#include "math.h"

int main () {

double number = 0.0 / 0.0;

if ( isnan ( number ) ) {
std::cout << "Is a number." << std::endl;
} else {
std::cout << "Is not a number." << std::endl;
}

}


Transcript of compilation attempt:

# g++ -Wall -o math.output -c math.cpp
math.cpp: In function 'int main()':
math.cpp:8: error: 'isnan' was not declared in this scope


This appears to be related to the "math.h" header file. I've noticed
several things including the fact that MINIX's port of GCC changed
some between MINIX releases 3.1.7 and 3.1.8 and that C++ this problem
did not appear in the experimental release of 3.1.8 but only in the
final release of 3.1.8.

Thank you,
pikpik

Alexander A. Gorodnev

unread,
Oct 30, 2010, 4:39:46 AM10/30/10
to min...@googlegroups.com
Hi,

Could you test the next fixes in your program?

#include <iostream>
#include <cmath>

int main () {

double number = 0.0 / 0.0;

if ( std::isnan ( number ) ) {


std::cout << "Is a number." << std::endl;
} else {
std::cout << "Is not a number." << std::endl;
}

}

Thanks,
Alexander

2010/10/30 pikpik <pikpi...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "minix3" group.
> To post to this group, send email to min...@googlegroups.com.
> To unsubscribe from this group, send email to minix3+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/minix3?hl=en.
>
>

pikpik

unread,
Oct 30, 2010, 12:43:54 PM10/30/10
to minix3
Hi,

On Oct 30, 4:39 am, "Alexander A. Gorodnev" <a.gorod...@gmail.com>
wrote:
> Hi,
>
> Could you test the next fixes in your program?
>
> #include <iostream>
> #include <cmath>
>
> int main () {
>
>  double number = 0.0 / 0.0;
>
>  if ( std::isnan ( number ) ) {
>    std::cout << "Is a number." << std::endl;
>  } else {
>    std::cout << "Is not a number." << std::endl;
>  }
>
> }
>
> Thanks,
> Alexander
>

Gladly!

Here are the results:

# g++ -Wall -o math.output -c math.cpp
math.cpp: In function 'int main()':
math.cpp:8: 'isnan' is not a member of 'std'


To me, it looks like "isnan" either is not available or is not in the
proper name-space.

Just to make sure GCC (G++) had everything available, I redid "make
gnu-includes gnu-libraries" in "/usr/src." However, it didn't seem to
have any effect.

Thank you,
pikpik

pikpik

unread,
Nov 3, 2010, 3:02:44 PM11/3/10
to minix3
Hi,

I'm happy to say that, with a small change to "math.h," I'm now able
to use "isnan" (and related functions) from "math.h" in C++! The
change might not be very correct, but it appears to be functional:
with it in place, the dependent parts of Google's V8 JavaScript Engine
now compile successfully.

Here's the change, inside "/usr/include/math.h" and "/usr/pkg/gcc44/
lib/gcc/i686-pc-minix/4.4.3/include-fixed/math.h":

[...hypot and others...]

Line 55: #if defined(_POSIX_SOURCE) /* STD-C? */ || \
Line 56: defined(__cplusplus)

[...isnan and others...]


This appears to work for me.
pikpik
Reply all
Reply to author
Forward
0 new messages