Page 1 of 2 12>
Topic Options
#70196 - 2002-09-24 03:42 PM Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Probably going to make an ass of myself here - and I know (think) this has been discussed before, but I just want to nail these floating point rules down ...

Shouldn't this expression produce the number 300:

? 600 * 0.5

I know theres a bunch of funky rules about this ... but thought (intuitively) that this would have worked.

-Shawn

Top
#70197 - 2002-09-24 03:45 PM Re: Floating Point - Should this simple expression work ?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Nope, since the first value is integer, the second value will betreated as integer, too. So, since the integer value of 0.5 is 0, you'll get 0 as answer. However if you try 0.5 * 600 you'll get 300 because the first number is a float.

In this case, the results are actually consistent with the KiXtart documentation.
_________________________
There are two types of vessels, submarines and targets.

Top
#70198 - 2002-09-24 03:46 PM Re: Floating Point - Should this simple expression work ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
still, jens is right but the integer value of 0.5 should be turned to 1...
according to math rules...
_________________________
!

download KiXnet

Top
#70199 - 2002-09-24 03:47 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
So then why does this not work:

? 0.0 + (600 * 0.5)

Top
#70200 - 2002-09-24 03:48 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
If I understand the rules, kixtart looks at the type of first variable & this sets the tone for processing the statement. Thus it does integer math here. Reverse the order & it will do floating point.

PS: The second formula doesn't work [Eek!] because as jooel says inside brackets the rules get applied from scratch. (I guess I should take time to read.)

[ 24. September 2002, 15:56: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#70201 - 2002-09-24 03:49 PM Re: Floating Point - Should this simple expression work ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shawn, because it first count the stuff in paranthesis.

jack, getting slow today?

{edit}
shawn, try it with:
? (0.0 + 600) * 0.5

[ 24. September 2002, 15:51: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#70202 - 2002-09-24 03:51 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
I am drinking coffee, & relaxing at this moment any small delay gets allows you guys to respond 10 times.
_________________________
Jack

Top
#70203 - 2002-09-24 03:54 PM Re: Floating Point - Should this simple expression work ?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Lonkero:
The conversion will go towards the nearest even integer for exact fractions of .5. Try this:
code:
? 0 + 0.5
? 0 + 1.5
? 0 + 2.5
? 0 + 3.5

the results will be 0,2,2,4

This is documented in the KiXtart 4.11 Manual under CINT().
_________________________
There are two types of vessels, submarines and targets.

Top
#70204 - 2002-09-24 03:55 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yes - reversing the order works nicely with numbers returned from COM objects:

$DomainList.Right = 0.30 * $Form.ClientWidth

thanks guys.

Top
#70205 - 2002-09-24 03:55 PM Re: Floating Point - Should this simple expression work ?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Math Rules don't apply in the KiXtart Universe [Smile]

This might actually imply that we can develop a working warp drive if we stay within the KiXtart Universe [Big Grin] [Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#70206 - 2002-09-24 03:56 PM Re: Floating Point - Should this simple expression work ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Because each expression is considered on it's own merits, and the 600*0.5 expression will be evaluated before the 0.0+() expression.

(0.0+600)*0.5 should give you 300 though.

We went through this pretty exhaustively with some good examples, but for the life of me I can't get the search engine to turn them up [Roll Eyes]

Beware however that one of the release candidates had a bug in the precedence when using "NOT"

{edit} Good grief! a veritable flood! {/edit}

[ 24. September 2002, 15:58: Message edited by: Richard Howarth ]

Top
#70207 - 2002-09-24 03:58 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Shawn,

You notice the attention you get! Moth's to a flame.
_________________________
Jack

Top
#70208 - 2002-09-24 03:59 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yeah - my take was that if an expression starts with a floating point number - it would return a floating point - and likewise, if it started with an integer, return a integer (yada-yada).

But what I didn't understand was that if an expression starts with an integer - any floating point number contained within are rounded up.

-Shawn

[ 24. September 2002, 16:01: Message edited by: Shawn ]

Top
#70209 - 2002-09-24 04:02 PM Re: Floating Point - Should this simple expression work ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, noticed that shawn is again the #1 poster on this board...

MCA's vacation had some influence after all [Wink]
_________________________
!

download KiXnet

Top
#70210 - 2002-09-24 04:04 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
Kixtart processes math expressions in a strictly left to right progression & at each step it converts the rightmost to variable type of the leftmost but as Jooel says brackets are processed first & inside the brackets the same left to right rules are followed & after the bracket is evaluated it returns to its left to right processing.

PS: I thought kixtart followed the standard rules for conversion from floating point to integer - it truncates.

Sorry I am so slow, but I am at work & distractions keep coming along.

[ 24. September 2002, 16:12: Message edited by: Jack Lothian ]
_________________________
Jack

Top
#70211 - 2002-09-24 04:14 PM Re: Floating Point - Should this simple expression work ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
quote:
Kixtart processes math expressions in a strictly left to right progression
Not quite right, this is only true where the operators have the same precedence.

KiXtart obeys standard operator preference, so in the expression:

code:
"10" + 5 * 2.5 = "1010"

Will give the result "1010", as the multiplication will be evaluated first due to operator precedence.

As the first number is an integer "5", the "2.5" is converted to an integer and the multiplication takes place, resulting in an integer "10".

Now, the addition may take place and the result is a string, because the first element in the expression is a string. This means a catenation "10" + "10" = "1010"

Top
#70212 - 2002-09-24 04:29 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
True, the complexities of precedence can seriously complicate an expression.
_________________________
Jack

Top
#70213 - 2002-09-24 04:33 PM Re: Floating Point - Should this simple expression work ?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Since it was not mentioned....

Use the command CDBL to convert a single int to a double.

? cdbl(2) * 3.2
? cdbl(600) * 0.5

Top
#70214 - 2002-09-24 05:10 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Bryce - good one - I was trying this:

? cdbl(600 * 0.5)

Well, I appreciate the rational and justification Ruud used in building these rules - the jist of which is to maintain 100% backward compatibility with older scripts. The goal i guess was to insure that legacy scripts would never return a float - under any circumstance.

But having said that - i don't see the harm in relaxing the rules so that if an expression "CONTAINED" a float - that the float wouldn't be rounded up.

But I guess older scripts could potentially accidently read a float within an expression ... say, a string from a text file or from the registry ... not too sure about that.

[ 24. September 2002, 17:11: Message edited by: Shawn ]

Top
#70215 - 2002-09-24 05:29 PM Re: Floating Point - Should this simple expression work ?
Jack Lothian Offline
MM club member
*****

Registered: 1999-10-22
Posts: 1169
Loc: Ottawa,Ontario, Canada
You are starting to track into one of the key issues in Golf24 - ensuring kixtart consistently used floating point. It is a complex issue.
_________________________
Jack

Top
Page 1 of 2 12>


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.072 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org