Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: casting constant value from float to unsigned short - compiler bugs? |
| Date | 2012-01-06 07:17 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <je6oom$tiu$1@dont-email.me> (permalink) |
| References | (5 earlier) <pan.2012.01.04.09.11.01.416000@nowhere.com> <rubrum-F1F8B0.23080204012012@news.albasani.net> <0.8f2bb956cd2606be95b2.20120105111551GMT.87ipkq5riw.fsf@bsb.me.uk> <je44us$dq5$1@dont-email.me> <rubrum-916339.16280105012012@news.albasani.net> |
On 01/05/2012 07:28 PM, Michael Press wrote: > In article <je44us$dq5$1@dont-email.me>, > James Kuyper <jameskuyper@verizon.net> wrote: > >> On 01/05/2012 06:15 AM, Ben Bacarisse wrote: >> ... >>> While I like nothing better that good barney about definitions, lets not >>> lose sight of the fact that the C standard is not at all ambiguous about >>> the conversion that sparked this thread. Talk of "readings" suggests >>> that there might be some doubt, but there isn't -- C's conversion from >>> floating to integer types "truncates towards zero". >> >> Michael has absolute certainty (justified or not) about the mathematical >> definition of "fractional part". Since the C standard provides no >> definition of it's own, > > It as good as does. > > the fractional part is discarded > (i.e., the value is truncated toward zero) No, that's not in the Definitions section, nor are the words "fractional part" italicized: those are the two methods used by the standard to identify a definition. Therefore: >> if there were a single definition of the term >> that is universally used in the mathematical community, then that one is >> the one that should apply. If his definition is the correct one, the >> standard is self-contradictory: it specifies both that "the fractional >> part is discarded" and that "the value is truncated toward zero". If that were the case, then that paragraph would be a prime example of why it's generically a bad idea for the standard to specify something twice. In reality, your use of the definite article in your phrase "the mathematical definition" seems to be unjustified - alternative definitions are in use. One point of view looks at the value that would print out as "-23.45", and parses it as having a sign factor of -1, an integer part of 23, a decimal point, and a fractional part of 45/100. Under that interpretation, "discarding the fractional part" means converting "-12.34" into "-12.", and is indeed equivalent to truncation toward zero. Therefore, this isn't a double specification; the truncation clause clarifies which one of the multiple definitions currently in use for "fractional part" is being used in the discard clause. > You introduce correctness. For the record, I am not at all > interested in correctness here. Good definitions are a > result of much thought and work. The only thing being defined here is the behavior, not the meaning of the terms used in that definition. You're right about good definitions, but one of requirements for a good definition, one of the reasons it requires careful thought, is that all of the terms used in that definition should be used correctly. > Presumably truncating toward zero in the C standard > is to reduce the number of cases where conversion leads to overflow. I can't be sure what the reason was. Personally, I've never written code where truncation of negative numbers toward zero was the desired behavior. In most cases when I've converted a floating point number that might be negative to an integer, what I wanted was lrint(x) (but instead, I had to settle for (long)floor(x+0.5), because our contract with our client requires use of C90 code); the second most common thing I've wanted is (long)floor(x) - I can't remember ever wanting the result that I would have gotten for negative values of x from (long)x. The Rationale only says "There was strong agreement in the C89 Committee that floating values should truncate toward zero when converted to an integer type, the specification adopted in the Standard. Although K&R 35 permitted negative floating values to truncate away from zero, no C89 Committee member knew of an implementation that functioned in such a manner.2" Footnote 2 says "The Committee has since learned of one such implementation." -- James Kuyper
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
casting constant value from float to unsigned short - compiler bugs? "news.aon.at" <mario_semo@hotmail.com> - 2011-12-02 10:06 +0100
Re: casting constant value from float to unsigned short - compiler bugs? jacob navia <jacob@spamsink.net> - 2011-12-02 10:34 +0100
Re: casting constant value from float to unsigned short - compiler bugs? Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-02 18:10 +0100
Re: casting constant value from float to unsigned short - compiler bugs? Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2011-12-02 22:36 +0000
Re: casting constant value from float to unsigned short - compiler bugs? jacob navia <jacob@spamsink.net> - 2011-12-03 00:45 +0100
Re: casting constant value from float to unsigned short - compiler bugs? pete <pfiland@mindspring.com> - 2011-12-02 19:43 -0500
Re: casting constant value from float to unsigned short - compiler bugs? pete <pfiland@mindspring.com> - 2011-12-02 19:49 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-12-03 01:51 +0100
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2011-12-03 11:51 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-03 19:08 +0100
Re: casting constant value from float to unsigned short - compiler bugs? Quentin Pope <qp19433@hotmail.NOSPAM.com> - 2011-12-03 19:06 +0000
Re: casting constant value from float to unsigned short - compiler bugs? Kaz Kylheku <kaz@kylheku.com> - 2011-12-03 19:14 +0000
Re: casting constant value from float to unsigned short - compiler bugs? Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-04 17:19 +0200
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2011-12-04 10:39 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2011-12-03 01:41 +0100
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-03 12:31 -0800
Re: casting constant value from float to unsigned short - compiler bugs? blp@cs.stanford.edu (Ben Pfaff) - 2012-01-03 12:38 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-06 11:38 -0800
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-06 15:10 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Keith Thompson <kst-u@mib.org> - 2012-01-03 12:49 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-04 15:14 -0800
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-04 19:12 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-04 23:04 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Keith Thompson <kst-u@mib.org> - 2012-01-05 02:43 -0800
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-05 07:14 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-06 11:39 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-05 16:14 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Keith Thompson <kst-u@mib.org> - 2012-01-05 16:44 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-06 11:30 -0800
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-06 15:24 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-26 09:14 -0800
Re: casting constant value from float to unsigned short - compiler bugs? gwowen <gwowen@gmail.com> - 2012-01-05 04:09 -0800
Re: casting constant value from float to unsigned short - compiler bugs? "io_x" <a@b.c.invalid> - 2012-01-05 16:32 +0100
Re: casting constant value from float to unsigned short - compiler bugs? Nobody <nobody@nowhere.com> - 2012-01-04 09:11 +0000
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-04 23:08 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-05 11:15 +0000
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-05 07:27 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-01-05 13:03 +0000
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-05 16:28 -0800
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2012-01-06 07:17 -0500
Re: casting constant value from float to unsigned short - compiler bugs? lawrence.jones@siemens.com - 2012-01-06 12:04 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-26 09:08 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Michael Press <rubrum@pacbell.net> - 2012-01-05 16:17 -0800
Re: casting constant value from float to unsigned short - compiler bugs? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-03 01:50 +0000
Re: casting constant value from float to unsigned short - compiler bugs? James Kuyper <jameskuyper@verizon.net> - 2011-12-02 06:41 -0500
Re: casting constant value from float to unsigned short - compiler bugs? Vincenzo Mercuri <vincenzo.mercuri@hotmail.it> - 2011-12-02 16:26 +0100
csiph-web