|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-07-18 08:06:00
| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Gabriel Dos Reis
| Sent: Thursday, July 17, 2003 10:36 PM
| To: Boost mailing list
| Subject: Re: [boost] Re: Re: is_nan - how to flag missing values?
|
| I can assist but I cannot volunteer to do the full work.
| -- Gaby
Thanks! Well how about considering just the Intel X86 and Ia64 processors for a
start?
Purely as an trivial example of the sorts of things that people might want to
do, I 'just' want to be able to create a fixed array (or other container) of
floating point values, initially make them some 'missing', fill in some with
'non-missing' values, and be able to calculate the count of 'good' and the sum,
ignoring missing values. And to be able to display the array as:
{1, 2, missing, 3}
So you suggest I need to decide a suitable NaN to represent 'missing'. My first
proposal was the Intel Indeterminate, for 32 FP 0xFFC00000, for 64 bit
FFF8000000000000 - but you didn't like that. It can never be the result of a X86
FP operation? There are also a wide choice of +ve and -ve qNaNs. (and sNaNs but
if a function is_missing is to be provided, these don't seem so sensible or
there is a risk of hardware exception bit being set and causing a probably
unwanted trap).
For IA64 FP registers there are pseudoNaNs (0x1FFFF 0.00....01 to 0.1..111)
which are said never to be the result of an arithmetic operation. But I am not
clear how this relates to 64 or 32 bit floating point types in memory.
So how do I chose?
Then I need floating-point as hex value testing functions, for example:
bool is_missingf(float); // Ugly suffix F and L :-((
bool is_missing(double);
bool is_missingl(long double);
or
bool is_missing<FPtype>(float);
(Similar problems to is_nan function(s))
so I can write code like
float values[4] = {1, 2, missing, 3}; // How to initialise nicely?
float sum = 0.f;
int count = 0;
for (int i = 0; i < n; i++)
{
cout << values[i] << endl; // missing values must display as "missing"
if (!is_missing(values[i])
{
count++;
sum += values[i];
}
}
// count should be 3 and sum 1 + 2 + 3 of course.
The stream part probably involves a derived version of num_put (and to allow
input of 1 2 "missing" 3 to be readcorrectly, num_get as well).
If I am foolish enough to use a missing value by mistake, the result will
(should) be a NaN, so I won't get a quietly misleading result.
(And lets say I'd also prefer NaNs to display as NotANumber, for which isnan()
will be needed, or something else of MY choice rather than the Microsoft choice
1.QNAN - and to be the same on other platforms too).
Suggestions most welcome?
Paul
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
Mobile mailto:pabristow_at_[hidden]
mailto:pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk