Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Decimal Numbers
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
*Worthy*
Critical Thinker




Joined: 11 Aug 2003
Posts: 186

PostPosted: Mon Aug 23, 2004 7:45 pm    Post subject: Reply with quote

6 * 3 / 2 = 9
3 / 2 * 6 = 9
3 * 6 / 2 = 9

Normally, you are right. But here's what will happen in the plotscripting compiler:

6 * 3 / 2 =
18 / 2 = 9

3 / 2 * 6 =
1 * 6 = 6

3 * 6 / 2 =
18 / 2 = 9

In math used outside of OHR, however, you are right. But the early rounding for plotscripting alters the end result. (Or so I think)

~Worthy
_________________
You can do whatever you want...but prison is full of people who make bad decisions.
Back to top
View user's profile Send private message Send e-mail AIM Address
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Mon Aug 23, 2004 7:48 pm    Post subject: Reply with quote

It does. A script in SG3 depends on this error.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Aug 23, 2004 10:14 pm    Post subject: Reply with quote

Quote:
Order of ops doesn't matter when you're only dealing with multiplication and division.


Other way around. You really only need to worry about this when you are dealing with operations of the same importance of order, such as multiplication and division, because in these cases the order in which the operations are done depends in which order you write them.

Quoting from plotscr.hsd:

Code:
define operator,begin
20 ^   exponent
30,mod,modulus
30 /   divide
30 *   multiply
40 --  subtract
40 +   add
50 ==  equal
50 <>  notequal
50 <<  lessthan
50 >>  greaterthan
50 <=  lessthanorequalto
50 >=  greaterthanorequalto
60,xor,xor
60,and,and
60,or,or
70,:=,setvariable
end


Operations with the smaller number are calculated first, two operations with the same value are calculated in whichever order you write them, where the danger is.
Of interest is 'and' and 'or', which as James pointed out recently, can be used incorrectly in conditional statements.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Flamer
The last guy on earth...




Joined: 04 Feb 2003
Posts: 725
Location: New Zealand (newly discovered)

PostPosted: Tue Aug 24, 2004 12:41 am    Post subject: Reply with quote

I don't think it's an error. I mean, Java does the same thing if you're working with integer variables(unless you convert it to double, string or other)
it only accepts integers and truncades the decimals out
_________________
If we were a pack of dogs, IM would be a grand Hound, CN would be a very ficious little pitball, and Giz...well, it doesn't matter breed he is, he'd still be a bitch Raspberry!
(no offense to anyone that was mentioned)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Tue Aug 24, 2004 12:58 am    Post subject: Reply with quote

Actually, that's true.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Inferior Minion
Metric Ruler



Joined: 03 Jan 2003
Posts: 741
Location: Santa Barbara, CA

PostPosted: Tue Aug 24, 2004 2:41 am    Post subject: Reply with quote

But it does matter depending on how the compiler handles integer division.

3 / 2 = 1.5

If the compiler truncates the integer mid calculation then 3 / 2 = 1.

Therefore 3 / 2 * 6 = 6 and 6 * 3 / 2 = 9
_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
Moogle1
Scourge of the Seas
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 15 Jul 2004
Posts: 3377
Location: Seattle, WA

PostPosted: Tue Aug 24, 2004 4:37 am    Post subject: Reply with quote

This is useful in some cases. Say you need to know if a number is divisible by another:

(x / 2 * 2 == x)

is true if x is divisible by 2, false otherwise.
_________________
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You can post new topics in this forum
You can 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


Powered by phpBB © 2001, 2005 phpBB Group