[patch] Add functions for isfinite, isnan, and isnormal; use them from error_db

Jules Bergmann jules at codesourcery.com
Wed Oct 25 20:12:36 UTC 2006


This patch adds view functions for isfinite, isnan, and isnormal that 
take a view of floating point type values (including complex) and return 
a view of bools.

To check if a view contains NaNs:

	if (anytrue(isnan(view)))
	  ...

To count the number of NaNs in a view:

	int count = sumval(isnan(view));

etc etc

This patch extends error_db to return 201 if either input view contains 
a NaN.  (Note that the largest value that error_db can return for two 
views that contain only finite numbers is 0).

The reason that error_db was not propagating the NaN value is that 
reductions like maxval do not reliably propagate NaNs.

Deep inside maxval there is a loop:

	maxval = X.get(0);
	for (i= 1 .. size)
	  if (X.get(i) > maxval)
	    maxval = X.get(i)

If X.get(i) is a NaN, the comparison is false and the value is skipped 
over.  If X.get(0) is NaN, this would be propagated.

We could change maxval to check for NaN:

	for (i = ...
	  if (X.get(i) > maxval || isnan(X.get(i)))
	    ..

but that is going down a murky path.  Primarily it would degrade 
performance.  It would also create differences when another library is 
used to perform maxval (such as SAL) that doesn't check for NaNs.

C-VSIPL has the concept of development and release modes for the 
libraries, with the idea that in development mode the library might do 
additional checks (such as check for NaNs) that aren't done in release 
mode.  At some future point we could do something along those lines, 
perhaps taking advantage of C++ capabilities, such as passing maxval a 
policy for NaN checking, the default being no NaN checking.

				-- Jules

-- 
Jules Bergmann
CodeSourcery
jules at codesourcery.com
(650) 331-3385 x705
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nan.diff
URL: <http://sourcerytools.com/pipermail/vsipl++/attachments/20061025/5c26c902/attachment.ksh>


More information about the vsipl++ mailing list