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 3 - Numerics in PowerPC Assembly Language
Chapter 13 - Assembly-Language Numeric Conversions


Conversions From Floating-Point to Integer Formats

To convert numbers in floating-point format to integer format, use one of two instructions:
fctiwConvert and round in current direction.
fctiwzConvert and round toward zero (truncate).

To convert double-format numbers to 32-bit integers, perform the following sequence of instructions:

lfd   f1,d(r2)    # load double float input into f1
fctiw f2,f1       # f2 is fixed 32-bit integer version of input
stfd  f2,d(r1)    # store f2 at location d + (r1)
lwz   r3,d+4(r1)  # r3 is fixed 32-bit integer version of input
To convert single-format numbers to 32-bit integers, perform the following sequence of instructions:

lfs   f1,d(r2)    # load single float input into f1
                  # input automatically converted to double format
fctiw f2,f1       # f2 is fixed 32-bit integer version of input
stfs  f2,d(r1)    # store f2 at location d + (r1)
lwz   r3,d+4(r1)  # r3 is fixed 32-bit integer version of input
To truncate double- or single-format numbers, replace fctiw in the above examples with fctiwz.

Note
The conversion instructions might raise floating-point exceptions. For more information, see the Motorola PowerPC 601 RISC Microprocessor User's Manual.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996