I know in c that 3/2 gets 1 and 3%2 is also 1,and i think this is
guaranteed by C99(is that true?),but on the other hand,3/2 may be 1
or 2,and 3%2 may be 1 and 1 respectively,it is implement
dependent,so,is my understanding of this true(positive division and
mod is guaranteed while negative is not)? thx for your help in
advance.. 7 6696
jackie wrote:
I know in c that 3/2 gets 1 and 3%2 is also 1,and i think this is
guaranteed by C99(is that true?),but on the other hand,3/2 may be 1
or 2,and 3%2 may be 1 and 1 respectively,it is implement
dependent,so,is my understanding of this true(positive division and
mod is guaranteed while negative is not)? thx for your help in
advance..
It depends on whether your implementation
conforms to C89 rules or C99 rules.
In C89, it is implementation defined:
If either operand is negative,
whether the result of the / operator is the largest integer
less than or equal to the algebraic quotient
or the smallest integer
greater than or equal to the algebraic quotient
is implementationdefined,
as is the sign of the result of the % operator.
In C99:
[#6] When integers are divided, the result of the / operator
is the algebraic quotient with any fractional part
discarded.78) If the quotient a/b is representable, the
expression (a/b)*b + a%b shall equal a.
78)This is often called ``truncation toward zero''.

pete
jackie wrote:
I know in c that 3/2 gets 1 and 3%2 is also 1,and i think this is
guaranteed by C99(is that true?),but on the other hand,3/2 may be 1
or 2,and 3%2 may be 1 and 1 respectively,it is implement
dependent,so,is my understanding of this true(positive division and
mod is guaranteed while negative is not)? thx for your help in
advance..
What you say was true for only in C90; in C99 section 6.5.5p6 says "When
integers are divided, the result of the / operator is the algebraic
quotient with any fractional part discarded.90)". The "90)" refers to
footnote 90, which says: 'This is often called ‘‘truncation toward zero"'.
What that means is that if the algebraic quotient is 1.5, the result 1
(the .5 is discarded). Since 1.5 gets rounded to 1, and 1.5 gets
rounded to 1, both rounded results are closer to 0 than the unrounded
results, which is why this is referred to as "toward zero".
This causes problems for me. When I use negative numbers in such
calculations, what I want, far more often than not, is what they call
"rounding to negative infinity"  1.5 gets rounded to 1, and 1.5 gets
rounded to 2  both results are closer to negative infinity than the
number before rounding. However, standardizing it to round toward zero
still makes things a lot easier for me than not standardizing it at all.
pete wrote:
jackie wrote:
>I know in c that 3/2 gets 1 and 3%2 is also 1,and i think this is guaranteed by C99(is that true?),but on the other hand,3/2 may be 1 or 2,and 3%2 may be 1 and 1 respectively,it is implement dependent,so,is my understanding of this true(positive division and mod is guaranteed while negative is not)? thx for your help in advance..
It depends on whether your implementation
conforms to C89 rules or C99 rules.
He specified C99.
Thanks pete and James Kuyper,ur replies really make life easier for
me,actually,i am a student from China,and i don't have the opportunity
to have a copy of C99,so when i try to make the program more
portable,sometimes i really don't know what the standards are.So
really thank you for ur help here.
jackie wrote:
Thanks pete and James Kuyper,ur replies really make life easier for
me,actually,i am a student from China,and i don't have the opportunity
to have a copy of C99,so when i try to make the program more
portable,sometimes i really don't know what the standards are.So
really thank you for ur help here.
Google for n1256.pdf, in case Google censored that for you, try http://www.openstd.org/jtc1/sc22/wg...docs/n1256.pdf
This the current C99 with TC1, TC2 and TC3 incorporated.
Bye, Jojo
Google for n1256.pdf, in case Google censored that for you, tryhttp://www.openstd.org/jtc1/sc22/wg14/www/docs/n1256.pdf
This the current C99 with TC1, TC2 and TC3 incorporated.
Bye, Jojo
thank u Joachim Schmitz,but what's the meaning of TC1,2,3? Is it still
a draft or it has already been approved? thx
jackie said:
>
>Google for n1256.pdf, in case Google censored that for you, tryhttp://www.openstd.org/jtc1/sc22/wg14/www/docs/n1256.pdf
This the current C99 with TC1, TC2 and TC3 incorporated.
Bye, Jojo
thank u Joachim Schmitz,but what's the meaning of TC1,2,3?
TCs are "Technical Corrigenda", i.e. corrections to the text of the
Standard.

Richard Heathfield <http://www.cpax.org.uk>
Email: http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place"  dmr 29 July 1999 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: martin 
last post by:
Hi,
We have a heavily used production server and a table which logs every
hit on a web site. This table has grown large over time and we want to
clear it down as efficiently as possible. We would...

by: Neil Monk 
last post by:
(sorry for xpost but news://macromedia.dreamweaver seem unable to help,
which I find astounding.)
Hi, I'm VERY new to DW MX 2004 (opk then, I'm new to DW..period!)
I'm sipmly trying to do the...

by: jimh 
last post by:
I'm not a SQL expert. I want to be able to write a stored procedure
that will return 'people who bought this product also bought this...'.
I have a user table that links to a transaction table...

by: Homer Simpson 
last post by:
Hi everyone,
I wrote a quick method to perform a calculation to determine the average of
two numbers. When 23 and 40 were used, the result was 31, not 31.5! I
discovered the problem, I was using...

by: seb.haase 
last post by:
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :(
On the otherhand I'm using Python as "Matlab...

by: krypto.wizard 
last post by:
Last month I appeared for an interview with EA sports and they asked
me this question.
How would you divide a number by 7 without using division operator ?
I did by doing a subtraction and...

by: mlcampeau 
last post by:
Hey guys,
I have been mulling over this problem for a few days and have yet to come up with a query that will give me the expected results. I am working on a database that stores employee...

by: Kevin K 
last post by:
Hey everyone, I'm new to python and am trying to do a little project
with it. I'm running into problems writing over a file. I read from
the file and loop through for a specfic case in which I...

by: =?Utf8?B?RXRoYW4gU3RyYXVzcw==?= 
last post by:
Hi,
Why does Math.Sqrt() only accept a double as a parameter? I would think
it would be just as happy with a decimal (or int, or float, or ....). I can
easily convert back and forth, but I am...

by: lllomh 
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{

by: DJRhino 
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

by: Aliciasmith 
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...

by: tracyyun 
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...

by: NeoPa 
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...

by: Teri B 
last post by:
Hi, I have created a subform Roles. In my course form the user selects the roles assigned to the course.
0netomany. One course many roles.
Then I created a report based on the Course form and...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...

by: isladogs 
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...

by: GKJR 
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
  