Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > question regarding % operator.

Reply
Thread Tools

question regarding % operator.

 
 
Tim Rentsch
Guest
Posts: n/a
 
      03-13-2012
Eric Sosman <(E-Mail Removed)> writes:

> On 3/12/2012 10:02 AM, somenath wrote:
>>
>> Many thanks for the great response.
>> So in case of 7/3 there also exist choices. It can be either 2 or 3.
>> But in C it is 2. So does it mean the choice was made to round toward
>> zero?

>
> Yes, even before C was standardized. The original K&R (now
> sometimes called "K&R I" to distinguish it from the later work)
> says
>
> When positive integers are divided truncation is toward
> zero, but the form of truncation is machine-dependent if
> either operand is negative. [...] It is always true
> that (a/b)*b + a%b is equal to a (if b is not 0).
>
> This particular choice was made for C in Ancient Times. One
> supposes that it was inspired by the behavior of the machines
> known to R, and that the leeway for negatives represented R's
> caution about machines where C might someday be implemented.
> The freedom was preserved in the original ANSI Standard, but
> by the time C99 rolled around the Committee apparently decided
> that "round toward minus infinity" machines were either non-
> existent or so rare as to be negligible.


I believe there was also some pressure to converge
on a single definition that would conform to other
standard languages, regardless of whether those
machines were negligibly rare or not.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question regarding viewing .asf files on my IP Lee Firefox 0 09-27-2005 03:36 PM
Basic VHDL question regarding pins googlinggoogler@hotmail.com VHDL 1 07-07-2005 11:10 PM
Question regarding newsgroups on Thunderbird Delete Firefox 5 02-12-2005 07:08 PM
Question regarding SP Patrick ASP .Net 7 01-25-2005 09:19 AM
Question Regarding Updating Firefox samx@north.net Firefox 2 07-09-2004 05:42 PM



Advertisments