Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: What is truncation for (singed) integer in C ? |
| Date | 2015-09-19 16:47 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <mtkhgq$fb3$1@dont-email.me> (permalink) |
| References | <6f66f235-1b11-4b0c-b2d8-c49ac3eac78e@googlegroups.com> |
On 9/19/2015 3:25 PM, fl wrote:
> Hi,
>
> I see the following on wikipedia and doubt about negative integer when
> truncating.
>
> https://en.wikipedia.org/wiki/Type_conversion
> ///////
> Data can be lost when floating-point representations are converted to integer
> representations as the fractional components of the floating-point values
> will be truncated (rounded towards zero)
> .......
>
> I agree for positive integer, truncation in C is towards 0. But for negative
> integer, it looks like away from '0'. For example, for a unsigned char 83H,
> one bit (LSB) truncation result will be 41H, whose non-truncation value
> (8-bit) is equal to 82H. The real value of 82H plus '1' is 83H. That is,
> 82H < 83H. For these negative numbers, it is not rounded towards zero.
>
> Is the above link not talking the same thing with my understanding?
The quote is about converting *floating-point* values to integer.
It's true that C's integer types have a few traps for the unwary
and inexperienced, though. Be especially careful of those singed
integers: They can *really* burn you!
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What is truncation for (singed) integer in C ? fl <rxjwg98@gmail.com> - 2015-09-19 12:25 -0700
Re: What is truncation for (singed) integer in C ? fir <profesor.fir@gmail.com> - 2015-09-19 12:55 -0700
Re: What is truncation for (singed) integer in C ? fir <profesor.fir@gmail.com> - 2015-09-19 13:20 -0700
Re: What is truncation for (singed) integer in C ? Geoff <geoff@invalid.invalid> - 2015-09-19 13:05 -0700
Re: What is truncation for (singed) integer in C ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-19 21:28 +0100
Re: What is truncation for (singed) integer in C ? Tim Prince <tprince@computer.org> - 2015-09-19 16:38 -0400
Re: What is truncation for (singed) integer in C ? James Kuyper <jameskuyper@verizon.net> - 2015-09-19 16:52 -0400
Re: What is truncation for (singed) integer in C ? Keith Thompson <kst-u@mib.org> - 2015-09-19 13:45 -0700
Re: What is truncation for (singed) integer in C ? James Kuyper <jameskuyper@verizon.net> - 2015-09-19 16:46 -0400
Re: What is truncation for (singed) integer in C ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-19 16:47 -0400
Re: What is truncation for (singed) integer in C ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-09-19 22:55 -0600
Re: What is truncation for (singed) integer in C ? James Kuyper <jameskuyper@verizon.net> - 2015-09-20 10:54 -0400
Re: What is truncation for (singed) integer in C ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-09-20 10:11 -0600
csiph-web