Topic: Defect Report: Floating-integral conversions (4.9/1) ambiguously


Author: musiphil@bawi.org (Seungbeom Kim)
Date: Mon, 13 Mar 2006 15:54:34 GMT
Raw View
Section 4.9 [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.

One could argue that these words have definite meanings established
outside the C++ context, but when I look up Wikipedia for these terms,
I find that truncation is defined as done using the floor function
and the fractional part of x is defined as x-floor(x). Therefore,
the meanings of "truncation" and "fractional part" as in the current
C++ standard are not common sense and needs to be defined precisely.
http://en.wikipedia.org/wiki/Truncation
http://en.wikipedia.org/wiki/Fractional_part

Proposed Resolution:
- Replace "truncates" with "truncates toward zero".
- 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.

--
Seungbeom Kim

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Alberto Ganesh Barbati <AlbertoBarbati@libero.it>
Date: Mon, 13 Mar 2006 14:26:34 CST
Raw View
Seungbeom Kim ha scritto:
> Section 4.9 [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.
>
> One could argue that these words have definite meanings established
> outside the C++ context, but when I look up Wikipedia for these terms,
> I find that truncation is defined as done using the floor function
> and the fractional part of x is defined as x-floor(x). Therefore,
> the meanings of "truncation" and "fractional part" as in the current
> C++ standard are not common sense and needs to be defined precisely.
> http://en.wikipedia.org/wiki/Truncation
> http://en.wikipedia.org/wiki/Fractional_part
>
> Proposed Resolution:
> - Replace "truncates" with "truncates toward zero".
> - 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.
>

For your reference, the corresponding paragraph in the C standard,
6.3.1.4/1, states:

"When a finite value of real floating type is converted to integer type
other than _Bool, the fractional part is discarded (i.e., the value is
truncated toward zero). [...]"

About your proposal, you must realize that the C++ Standard includes as
a *normative* reference the document ISO/IEC 2382 "Information
technology     Vocabulary". I don't have access to such document, but if
it contained a definition for the terms "truncation" and "fractional
part" then there would be no need for clarification. The fact that other
sources give a different definition of some terms would not be relevant
in that case.

Ganesh

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]