Subject: Re: Documentation of abs(3), div(3) etc.
To: Christian Biere <christianbiere@gmx.de>
From: Roland Illig <roland.illig@gmx.de>
List: tech-misc
Date: 02/07/2007 19:33:39
Christian Biere wrote:
> Hi,
> 
> the manpages for abs(3) and its variants define behavior for the "most negative
> integer" whereas the standard explicity states that the behavior is undefined
> if the result cannot be represented.
> 
> This is a lie anyway because the code looks like
> 
> 	return a < 0 ? -a : a;
> 
> whereas it obviously means
> 
> 	return a < 0 ? -(unsigned)a : a;

The C standard may say that the behavior is undefined, but that doesn't 
prevent an implementation from defining it. Assuming that the developers 
who wrote the man pages had checked the compiler's documentation as well 
as the documentation of all the hardware platforms NetBSD supports, and 
assuming further that all these platforms behave the same, there is 
nothing wrong with that documentation.

Of course, there should be test suites for these functions, making sure 
that the behavior indeed matches the documentation.

Roland

> I have attached a patch for the manpages. I've also changed "BUGS" to "CAVEAT"
> because these aren't bugs, it's broken by design.

You mean, two's complement is broken by design? ;)

Roland