libyasm
Macros | Functions
floatnum.h File Reference

YASM floating point (IEEE) interface. More...

Go to the source code of this file.

Functions

YASM_LIB_DECL void yasm_floatnum_initialize (void)
 Initialize floatnum internal data structures. More...
 
YASM_LIB_DECL void yasm_floatnum_cleanup (void)
 Clean up internal floatnum allocations. More...
 
YASM_LIB_DECL yasm_floatnumyasm_floatnum_create (const char *str)
 Create a new floatnum from a decimal string. More...
 
YASM_LIB_DECL yasm_floatnumyasm_floatnum_copy (const yasm_floatnum *flt)
 Duplicate a floatnum. More...
 
YASM_LIB_DECL void yasm_floatnum_destroy (yasm_floatnum *flt)
 Destroy (free allocated memory for) a floatnum. More...
 
YASM_LIB_DECL int yasm_floatnum_calc (yasm_floatnum *acc, yasm_expr_op op, yasm_floatnum *operand)
 Floating point calculation function: acc = acc op operand. More...
 
YASM_LIB_DECL int yasm_floatnum_get_int (const yasm_floatnum *flt, unsigned long *ret_val)
 Convert a floatnum to single-precision and return as 32-bit value. More...
 
YASM_LIB_DECL int yasm_floatnum_get_sized (const yasm_floatnum *flt, unsigned char *ptr, size_t destsize, size_t valsize, size_t shift, int bigendian, int warn)
 Output a yasm_floatnum to buffer in little-endian or big-endian. More...
 
YASM_LIB_DECL int yasm_floatnum_check_size (const yasm_floatnum *flt, size_t size)
 Basic check to see if size is valid for flt conversion (using yasm_floatnum_get_sized()). More...
 
YASM_LIB_DECL void yasm_floatnum_print (const yasm_floatnum *flt, FILE *f)
 Print various representations of a floatnum. More...
 

Detailed Description

YASM floating point (IEEE) interface.

Definition in file floatnum.h.

Function Documentation

YASM_LIB_DECL int yasm_floatnum_calc ( yasm_floatnum acc,
yasm_expr_op  op,
yasm_floatnum operand 
)

Floating point calculation function: acc = acc op operand.

Note
Not all operations in yasm_expr_op may be supported; unsupported operations will result in an error.
Parameters
accfloatnum accumulator
opoperation
operandfloatnum operand
Returns
Nonzero on error.
YASM_LIB_DECL int yasm_floatnum_check_size ( const yasm_floatnum flt,
size_t  size 
)

Basic check to see if size is valid for flt conversion (using yasm_floatnum_get_sized()).

Doesn't actually check for underflow/overflow but rather checks for size=32,64,80 (at present).

Parameters
fltfloatnum
sizenumber of bits of output space
Returns
1 if valid size, 0 if invalid size.
YASM_LIB_DECL void yasm_floatnum_cleanup ( void  )

Clean up internal floatnum allocations.

YASM_LIB_DECL yasm_floatnum* yasm_floatnum_copy ( const yasm_floatnum flt)

Duplicate a floatnum.

Parameters
fltfloatnum
Returns
Newly allocated floatnum with the same value as flt.
YASM_LIB_DECL yasm_floatnum* yasm_floatnum_create ( const char *  str)

Create a new floatnum from a decimal string.

The input string must be in standard C representation ([+-]123.456e[-+]789).

Parameters
strfloating point decimal string
Returns
Newly allocated floatnum.
YASM_LIB_DECL void yasm_floatnum_destroy ( yasm_floatnum flt)

Destroy (free allocated memory for) a floatnum.

Parameters
fltfloatnum
YASM_LIB_DECL int yasm_floatnum_get_int ( const yasm_floatnum flt,
unsigned long *  ret_val 
)

Convert a floatnum to single-precision and return as 32-bit value.

The 32-bit value is a "standard" C value (eg, of unknown endian).

Parameters
fltfloatnum
ret_valpointer to storage for 32-bit output
Returns
Nonzero if flt can't fit into single precision: -1 if underflow occurred, 1 if overflow occurred.
YASM_LIB_DECL int yasm_floatnum_get_sized ( const yasm_floatnum flt,
unsigned char *  ptr,
size_t  destsize,
size_t  valsize,
size_t  shift,
int  bigendian,
int  warn 
)

Output a yasm_floatnum to buffer in little-endian or big-endian.

Puts the value into the least significant bits of the destination, or may be shifted into more significant bits by the shift parameter. The destination bits are cleared before being set. [0] should be the first byte output to the file.

Note
Not all sizes are valid. Currently, only 32 (single-precision), 64 (double-precision), and 80 (extended-precision) are valid sizes. Use yasm_floatnum_check_size() to check for supported sizes.
Parameters
fltfloatnum
ptrpointer to storage for size bytes of output
destsizedestination size (in bytes)
valsizesize (in bits)
shiftleft shift (in bits)
bigendianendianness (nonzero=big, zero=little)
warnenables standard overflow/underflow warnings
Returns
Nonzero if flt can't fit into the specified precision: -1 if underflow occurred, 1 if overflow occurred.
YASM_LIB_DECL void yasm_floatnum_initialize ( void  )

Initialize floatnum internal data structures.

YASM_LIB_DECL void yasm_floatnum_print ( const yasm_floatnum flt,
FILE *  f 
)

Print various representations of a floatnum.

For debugging purposes only.

Parameters
ffile
fltfloatnum