sign of infinity and isinf()?
Stefan Farfeleder
stefanf at FreeBSD.org
Sun Jun 13 16:29:43 GMT 2004
On Sun, Jun 13, 2004 at 09:06:30AM -0700, Steve Kargl wrote:
> I don't have a copy of the C99 standard only Harbison and Steele,
> 5th Ed. On page 440, they state: "The isinf macro returns a nonzero
> value if and only if its argument is infinite (with any sign)."
This is what C99 says:
# Description
# The isinf macro determines whether its argument value is an infinity
# (positive or negative). First, an argument represented in a format
# wider than its semantic type is converted to its semantic type. Then
# determination is based on the type of the argument.
# Returns
# The isinf macro returns a nonzero value if and only if its argument
# has an infinite value.
I agree that the text from H&S is a bit ambiguous.
> The program below does note return the sign.
> kargl[243] gcc -o a -O a.c
> kargl[244] ./a
> -inf
> 1
> #include <stdio.h>
> #include <math.h>
>
> int main(void) {
> double x, y;
> x = -1.;
> y = 0.;
> x /= y;
> printf("%lf\n", x);
> printf("%d\n", isinf(x));
> }
Since 1 is a nonzero value, this is correct.
Cheers,
Stefan
More information about the freebsd-standards
mailing list