Thread Links | Date Links | ||||
---|---|---|---|---|---|
Thread Prev | Thread Next | Thread Index | Date Prev | Date Next | Date Index |
BK> To do so would require a facility for rounding the text value 0.1 down into the binary format and also rounding it up.
BK> . . .
BK> I don't think it is readily accessible by default in common programming languages.
The 1999 version of the C standard has functions to get and set the rounding mode. They can be called from C++ or from Fortran. Fortran also has its own IEEE modules which could be used.
For example. in an environment that supports changing the rounding mode (as opposed to having static rounding modes), a function something like the (completely untested) following should work.
#include <stdlib.h>
#include <fenv.h>
typedef struct interval_s
{
double lower;
double upper;
} interval_t;
interval_t text2interval (const char const* text)
{
#pragma STDC FENV_ACCESS ON
interval_t result;
int original_rounding_mode = fegetround ( );
(void) fesetround (FE_DOWNWARD);
result.lower = atof (text);
(void) fesetround (FE_UPWARD);
result.upper = atof (text);
(void) fesetround (original_rounding_mode);
return result;
}