Files
2025-10-25 03:02:53 +03:00

54 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[conv.fpint]
# 7 Expressions [[expr]](./#expr)
## 7.3 Standard conversions [[conv]](conv#fpint)
### 7.3.11 Floating-integral conversions [conv.fpint]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L989)
A prvalue of a floating-point type can be converted to a prvalue of an
integer type[.](#1.sentence-1)
The conversion truncates; that is, the fractional part is
discarded[.](#1.sentence-2)
The behavior is undefined if the truncated value cannot be represented
in the destination type[.](#1.sentence-3)
[*Note [1](#note-1)*:
If the destination type is bool, see [[conv.bool]](conv.bool "7.3.15Boolean conversions")[.](#1.sentence-4)
— *end note*]
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L1001)
A prvalue of an integer type or of an unscoped enumeration type can be converted to
a prvalue of a floating-point type[.](#2.sentence-1)
The result is exact if possible[.](#2.sentence-2)
If the value being
converted is in the range of values that can be represented but the value cannot be
represented exactly, it is an implementation-defined choice of either the next lower or higher representable
value[.](#2.sentence-3)
[*Note [2](#note-2)*:
Loss of precision occurs if the integral value cannot be represented
exactly as a value of the floating-point type[.](#2.sentence-4)
— *end note*]
If the value being converted is
outside the range of values that can be represented, the behavior is undefined[.](#2.sentence-5)
If the
source type is bool, the value false is converted to zero and the valuetrue is converted to one[.](#2.sentence-6)