> > > 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.