Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 9 - Conversion Functions


Conversions Summary

This section summarizes the C constants, macros, functions, and type definitions associated with converting floating-point values.

C Summary

Constants

#define      SIGDIGLEN      36            /* significant decimal digits */
#define      DECSTROUTLEN   80            /* max length for dec2str output */
#define      FLOATDECIMAL   ((char)(0))
#define      FIXEDDECIMAL   ((char)(1))

Data Types

struct decimal 
{
   char sgn;                              /* sign 0 for +, 1 for - */
   char unused;
   short exp;                             /* decimal exponent */
   struct
   {
      unsigned char length;
      unsigned char text[SIGDIGLEN];      /* significant digits */
      unsigned char unused;
   } sig;
};
typedef struct decimal decimal;
struct decform 
{
   char style;                         /* FLOATDECIMAL or FIXEDDECIMAL */
   char unused;
   short digits;
};
typedef struct decform decform;

Conversion Routines

Converting Floating-Point Formats to Integer Formats

long int rinttol(double_t x);
long int roundtol(double_t x);

Rounding Floating-Point Numbers to Integers

double_t ceil(double_t x);
double_t floor(double_t x); 
double_t nearbyint(double_t x);
double_t round(double_t x);
double_t trunc(double_t x);

Converting Decimal Numbers to Binary Numbers

float dec2f(const decimal *d);
double_t dec2num(const decimal *d);
long double dec2numl(const decimal *d);
short int dec2s(const decimal *d);
long int dec2l(const decimal *d);

Converting Binary Numbers to Decimal Numbers

void num2dec(const decform *f, double_t x, decimal *d);
void num2decl(const decform *f, long double x, decimal *d);

Converting Between Decimal Formats

void dec2str(const decform *f, const decimal *d, char *s);
void str2dec(const char *s, short *ix, decimal *d, 
short *vp); 


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996