 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Seungbeom Kim Guest
|
Posted: Mon Mar 13, 2006 4:06 pm Post subject: Defect Report: Floating-integral conversions (4.9/1) ambiguo |
|
|
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 ] |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Mar 13, 2006 5:35 pm Post subject: Re: Defect Report: Floating-integral conversions (4.9/1) amb |
|
|
Seungbeom Kim wrote:
| Quote: | 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
|
My understanding is that "truncation" refers to truncating the series
which defines a number in terms of the values of it's digits by
discarding all of the digits after the decimal point, which is
equivalent to setting them to 0. This corresponds to "rounding toward
zero", not "rounding downward". The digits after the decimal point are
what is called the "fractional part", and "discarding the fractional
part" refers to the process of setting those digits to 0. I suspect
that the section you cite from the standard was written by someone
sharing the same (mis?)conception. At the very least, this indicates
that there's a difference of opinion on the matter, which argues in
favor of clarification.
| Quote: | Proposed Resolution:
- Replace "truncates" with "truncates toward zero".
|
I'd prefer "rounds toward zero"; with my understanding of the word
"truncate", "truncates toward zero" would be redundant.
---
[ 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 ] |
|
| Back to top |
|
 |
Alberto Ganesh Barbati Guest
|
Posted: Mon Mar 13, 2006 8:26 pm Post subject: Re: Defect Report: Floating-integral conversions (4.9/1) amb |
|
|
Seungbeom Kim ha scritto:
| Quote: | 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 ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|