Important: The information in this document is obsolete and should not be used for new development.
Conversions From Floating-Point to Integer Formats
To convert numbers in floating-point format to integer format, use one of two instructions:
fctiw Convert and round in current direction. fctiwz Convert 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 inputTo 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 inputTo truncate double- or single-format numbers, replacefctiw
in the above examples withfctiwz
.
- Note
- The conversion instructions might raise floating-point exceptions. For more information, see the Motorola PowerPC 601 RISC Microprocessor User's Manual.