Title
Conversion of negative floating point values to integer type
Status
nad
Section
7.3.11 [conv.fpint]
Submitter
Seungbeom Kim

Created on 2006-03-13.00:00:00 last changed 219 months ago

Messages

Date: 2006-10-15.00:00:00

Rationale (October, 2006):

The specification is clear enough: “fractional part” refers to the digits following the decimal point, so that -3.14 converted to int becomes -3.

Date: 2022-11-20.07:54:16

Section 7.3.11 [conv.fpint] paragraph 1 states:

An rvalue of a floating point type can be converted to an rvalue of an integer type. The conversion truncates; that is, the fractional part is discarded.

Here, the concepts of “truncation” and “fractional part” seem to be used without precise definitions. When -3.14 is converted into an integer, is the truncation toward zero or away from zero? Is the fractional part -0.14 or 0.86? The standard seem to give no clear answer to these.

Suggested resolution:

  1. Replace “truncates” with “truncates toward zero.”

  2. Replace “the fractional part” with “the fractional part (where that of x is defined as x-floor(x) for nonnegative x and x-ceiling(x) for negative x);” there should be a better wording for this, or the entire statement “that is, the fractional part is discarded” can be removed, once the meaning of “truncation” becomes unambiguous as above.

History
Date User Action Args
2006-11-05 00:00:00adminsetmessages: + msg1453
2006-11-05 00:00:00adminsetstatus: open -> nad
2006-03-13 00:00:00admincreate