Listing 6: Fragment from C++ header file qfloat.h
// Cephes Math Library Release 2.4: April, 1996
// Copyright 1996 by Stephen L. Mosier.
struct qfloatstruct
{
unsigned short ar[12];
};
extern "C"
{
void qclear (qfloatstruct *);
void e24toq (const float *, qfloatstruct *);
void etoq (const double *, qfloatstruct *);
void e64toq (const long double *, qfloatstruct *);
void ltoq (long int *, qfloatstruct *);
void asctoq (const char *, qfloatstruct *);
}
class qfloat
{
public:
qfloatstruct a;
// ------------
// Constructor.
// ------------
qfloat () {};
// qfloat () {qclear(&a);};
// ----------------------------------------
// Conversions from base classes to qfloat.
// ----------------------------------------
qfloat (float x) {e24toq (&x, &a);}
qfloat (double x) {etoq (&x, &a);}
qfloat (long double x) {e64toq (&x, &a);}
// ------------------------------------------
// qfloat (long double x) {e113toq (&x, &a);} // 128-bit
// ------------------------------------------
qfloat (long int x) {ltoq (&x, &a);}
qfloat (int x) {long lx = x; ltoq (&lx, &a);}
// ----------------------------------------------
// For conversion and assignment x = "1.234e4321"
// ----------------------------------------------
qfloat (char *x) {asctoq (x, &a);}
// -------------------------------------------------------
// Type conversion to a base class is not possible in C++,
// so you have to use these functions instead, e.g.
//
// int i = xtoi(q);
//
// to convert extended precision data to integer.
// -------------------------------------------------------
friend int xtoi (qfloat);
friend long xtol (qfloat);
friend float xtof (qfloat);
friend double xtod (qfloat);
friend long double xtold (qfloat);
};
/* End of File */