problem with sqrt and errno, FreeBSD release 4.3

problem with sqrt and errno, FreeBSD release 4.3

Post by Fred Richa » Thu, 21 Jun 2001 02:45:25



system (pentium 133)
--------------------

bleu temp %uname -a
FreeBSD bleu.far.org 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Mon Jun 11

i386

the problem
-----------
errno doesn't seem to be set correcly with the sqrt function.  I've
looked at other libm functions (eg, pow), and they don't work either.
However, errno is being set OK by other libc functions like
"strtol()", see code below.

code example
------------
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>

/********* compile and results ***************************
   % cc foo.c -o foo -Wall -lm

   % ./foo
     strtol failed: Result too large
     NaN
**********************************************************/

int main()
{
    long n;
    double x;
    char *cptr;

    errno = 0;
    n = strtol("fffffffffffffffffffffffff", &cptr, 16);
    if(errno)
        perror("strtol failed");
    else
        printf("%li\n", n);

    errno = 0;
    x = sqrt(-1);
    if(errno)
        perror("sqrt failed");
    else
        printf("%f\n", x);

    return 0;

Quote:}

any help would be appreciated.
--
Fred Richard
 
 
 

problem with sqrt and errno, FreeBSD release 4.3

Post by Lowell Gilber » Thu, 21 Jun 2001 07:16:52


comp.unix.bsd.freebsd is not widely carried (it was never "officially"
created); comp.unix.bsd.freebsd.misc is usually a better bet.


> the problem
> -----------
> errno doesn't seem to be set correcly with the sqrt function.  I've
> looked at other libm functions (eg, pow), and they don't work either.
> However, errno is being set OK by other libc functions like
> "strtol()", see code below.

Looks fine to me.  Nothing says that errno has to be set to DOM_ERR on
a domain error.  Returning "Not a Number" is perfectly within the
acceptable behaviour for the C language.

 
 
 

problem with sqrt and errno, FreeBSD release 4.3

Post by Fred Richa » Thu, 21 Jun 2001 10:09:30



> comp.unix.bsd.freebsd is not widely carried (it was never "officially"
> created); comp.unix.bsd.freebsd.misc is usually a better bet.

thanks.  I posted this via google, first time for me via that portal
and I thought it was sent to the ".misc" newsgroup -- my mistake (i've
read the ".misc" newsgroup from time to time).


> > the problem
> > -----------
> > errno doesn't seem to be set correcly with the sqrt function.  I've
> > looked at other libm functions (eg, pow), and they don't work either.
> > However, errno is being set OK by other libc functions like
> > "strtol()", see code below.

> Looks fine to me.  Nothing says that errno has to be set to DOM_ERR on
> a domain error.  Returning "Not a Number" is perfectly within the
> acceptable behaviour for the C language.

I was looking at the FreeBSD man pages for sqrt() and pow() and the C
reference book known as the ARM when I got the idea that errno should
be set.  still looks like a problem to me.

thanks.
--
Fred Richard

 
 
 

problem with sqrt and errno, FreeBSD release 4.3

Post by Lowell Gilber » Fri, 22 Jun 2001 00:29:04




> > > the problem
> > > -----------
> > > errno doesn't seem to be set correcly with the sqrt function.  I've
> > > looked at other libm functions (eg, pow), and they don't work either.
> > > However, errno is being set OK by other libc functions like
> > > "strtol()", see code below.

> > Looks fine to me.  Nothing says that errno has to be set to DOM_ERR on
> > a domain error.  Returning "Not a Number" is perfectly within the
> > acceptable behaviour for the C language.

> I was looking at the FreeBSD man pages for sqrt() and pow() and the C
> reference book known as the ARM when I got the idea that errno should
> be set.  still looks like a problem to me.

The man page only mentions errno in reference to specific processors
on which FreeBSD doesn't run at all.  The book you're mentioning is
presumably Harbison & Steele, which does does seem to indicate that
you are correct.
However, the latest standard includes the following language:

    For all functions, a domain error occurs if an input argument is outside
    the domain over which the mathematical function is defined. The
    description of each function lists any required domain errors; an
    implementation may define additional domain errors, provided that such
    errors are consistent with the mathematical definition of the
    function.194) On a domain error, the function returns an
    implementation-defined value; if the integer expression math_errhandling
    & MATH_ERRNO is nonzero, the integer expression errno acquires the value
    EDOM; if the integer expression math_errhandling & MATH_ERREXCEPT is
    nonzero, the invalid floating-point exception is raised.

The previous standard didn't even require the ability to check *if* errno
would be set.  Neither FreeBSD nor any other system at my disposal do
implement it yet, incidentally, regardless of whether they set errno
on domain errors.

Therefore, I don't think FreeBSD's current behaviour is technically
incorrect.  That doesn't mean that it can't be changed -- the other systems
which do what you want are also conformant.  Therefore, I don't think
anyone is going to change the library function for you, but if you
submit patches, they may well be accepted.

Be well.

 
 
 

1. Xamian on FreeBSD 4.3 || X 4.1.0 on FreeBSD 4.3

is this possible?
i downloaded the X 4.1.0 binaries and all i can run is X or XFree86 ?
its config'd and everything to 1600x1400 but i have no dri support(ati
radeon) and i have to startx with & export display then start my window
manager, there must be a better way to do this?

2. what are bogo-mips ?

3. Problem with natd, running on FreeBSD 4.3-RELEASE

4. trn and mush

5. Problem with FreeBSD 4.3-RELEASE

6. NEW security Web-Page

7. When is FreeBSD 4.3 released?

8. NVT write errors with TinyTerm and OSR5

9. how to install net card : cs8920 ( onboard in Ibm) in freebsd 4.3 release?

10. PS/2 mouse not working FreeBSD 4.3 RELEASE

11. FreeBSD 4.3 released

12. FreeBSD 4.3-RELEASE: Various applications core-dump

13. problem with sqrt() and errno