## Floating-point to Integer Conversion Overview
IEEE 754 does not specify what results are obtained when converting a NaN
or out-of-range floating-point value to integer, so different programming
languages and ISAs have made different choices. The different conversion
modes supported by the `cffpr` instruction are as follows:
* P-Type:
Used by most other PowerISA instructions,
as well as commonly used floating-point to integer conversions on x86.
* S-Type:
Used for several notable programming languages:
* Java's conversion from `float`/`double` to `long`/`int`[^java_fp_to_int]
* Rust's `as` operator[^rust_as_operator]
* LLVM's `llvm.fptosi.sat`[^llvm_fptosi_sat] and
`llvm.fptoui.sat`[^llvm_fptoui_sat] intrinsics
* SPIR-V's OpenCL dialect's `OpConvertFToU`[^SPIRV_OpConvertFToU] and
`OpConvertFToS`[^SPIRV_OpConvertFToS] instructions when decorated with
the `SaturatedConversion`[^SPIRV_SaturatedConversion] decorator.
* Also WebAssembly's `trunc_sat_u`[^trunc_sat_u] and
`trunc_sat_s`[^trunc_sat_s] instructions,
* E-Type:
Used for ECMAScript's `ToInt32` abstract operation[^ECMAScript_ToInt32].
Also implemented in ARMv8.3A as the `FJCVTZS` instruction[^ARM_FJCVTZS].
[^trunc_sat_u]: WASM's `trunc_sat_u`:
[^trunc_sat_s]: WASM's `trunc_sat_s`:
[^java_fp_to_int]: Java `float`/`double` to `long`/`int` conversion:
[^rust_as_operator]: Rust's `as` operator:
[^llvm_fptosi_sat]: LLVM's `llvm.fptosi.sat` intrinsic:
[^llvm_fptoui_sat]: LLVM's `llvm.fptoui.sat` intrinsic:
[^SPIRV_OpConvertFToU]: SPIR-V's `OpConvertFToU` instruction:
[^SPIRV_OpConvertFToS]: SPIR-V's `OpConvertFToS` instruction:
[^SPIRV_SaturatedConversion]: SPIR-V's `SaturatedConversion` decorator:
[^ECMAScript_ToInt32]: ECMAScript's `ToInt32` abstract operation:
[^ARM_FJCVTZS]: ARM's `FJCVTZS` instruction:
### Floating-point to Integer Conversion Semantics Summary
Let `round` be the result of `bfp_ROUND_TO_INTEGER(rmode, input)`.
Let `w` be the number of bits in the result's type.
The result of Floating-point to Integer conversion is as follows:
```
+------+------+---------------------------------------------------------------+
|Type| Result | Category of rounding |
| | Sign +----------+-----------+----------+-----------+---------+-------+
| | | NaN | +Inf | -Inf | > Max | < Min | Else |
| | | | | | Possible | Possible| |
| | | | | | Result | Result | |
+----+--------+----------+-----------+----------+-----------+---------+-------+
| P |Unsigned| 0 | 2^w - 1 | 0 | 2^w - 1 | 0 | round |
| +--------+----------+-----------+----------+-----------+---------+-------+
| | Signed | -2^(w-1) | 2^(w-1)-1 | -2^(w-1) | 2^(w-1)-1 | -2^(w-1)| round |
+----+--------+----------+-----------+----------+-----------+---------+-------+
| S |Unsigned| 0 | 2^w - 1 | 0 | 2^w - 1 | 0 | round |
| +--------+----------+-----------+----------+-----------+---------+-------+
| | Signed | 0 | 2^(w-1)-1 | -2^(w-1) | 2^(w-1)-1 | -2^(w-1)| round |
+----+--------+----------+-----------+----------+-----------+---------+-------+
| E | Either | 0 | round & (2^w - 1) |
+----+--------+---------------------------------+-----------------------------+
```