Page 2 of 2 <12
Topic Options
#70216 - 2002-09-24 05:51 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:
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.
Don't forget it's not just integers and doubles we are talking about - there's unassigned variables and strings too.

Should an expression containing a string variable be considered as a string expression? Should an expression containing an unassigned (null) variable aways evaluate to null?

As far as KiXtart (or any other language) is concerned an expression at it's most complex is always a pair of operands seperated by an operator. The operand may be a variable or constant or another expression.

This means that at the parsing/execution stage a maximum of two operands will be considered - there is no look forward to determine whatever else is in the original expression.

The use of functions returning various data types complicate the issue still further.

It is far better to stick with the existing rules, consistantly adhered to (bugs notwithstanding [Wink] )

The rule is:
In any binary expression the operand on the right is converted to the same type as the operand on the left

Just follow the rules of precedence and the rule always holds true.

If you want to get a real headache, look up the YACC and Bison utilities to get a view of how most modern compilers and interpreters work.

Top
#70217 - 2002-09-24 06:02 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Compositely composed, but I think what I (may) be suggesting is:

The result of any binary expression will be converted to the same type as the operand on the left

Does this rule make sense ? Is it a better rule or will it lead to .... trouble !

[ 24. September 2002, 18:10: Message edited by: Shawn ]

Top
#70218 - 2002-09-24 06:36 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
The proplem is the left & right may be different types of variables so what is the result in this case? They must both be the same type to derive an answer.
_________________________
Jack

Top
#70219 - 2002-09-24 07:50 PM Re: Floating Point - Should this simple expression work ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Jack, your point is taken - so maybe I could suggest a grand new unified theory for Kixtart expressions:

In any binary expression the operand on the right is converted to the same type as the operand on the left and the result - converted to that type as well.

[shrug ala rclarke's avitar]

[ 24. September 2002, 19:52: Message edited by: Shawn ]

Top
#70220 - 2002-09-24 07:57 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 would expect kixtart to give "1" + 2="12". My wife who is a school math teacher would probably say it is obviously 3.

I am not sure I understand your grand unified rule - Isn't this kixtart's actual rule. Are you proposing a possible new rule or summarizing the current one?

[ 24. September 2002, 19:58: Message edited by: Jack Lothian ]
_________________________
Jack

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

Registered: 1999-08-13
Posts: 8611
Told you I'd make an ass out of myself [Wink] I thought I was proposing until I realized I was summarizing ... my head hurts.
Top
#70222 - 2002-09-24 08:17 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
One of my favourite quotes is:

quote:


No one is exempt from taking nonsense;
the only misfortune is to do it solemnly
- Montaigne

If you can laugh at yourself you aren't a fool or an ass.
_________________________
Jack

Top
#70223 - 2002-09-24 08:39 PM Re: Floating Point - Should this simple expression work ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
As long as we don't talk as much as we take... [Wink]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#70224 - 2002-09-25 10:13 AM Re: Floating Point - Should this simple expression work ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Hmmm... I didn't word the rule very well.

Of course the operand (variable, constant, function result) is not actually converted - the value of the operand which is on the internal processing stack is converted.

It'd be a nasty surprise if your variables' type was converted because it was on the right hand side of an expression [Eek!]

The rule is more properly:
In any binary expression the value of the operand on the right is converted to the same type as the operand on the left

There is probably a better way of putting it though.

Top
#70225 - 2002-09-29 12:02 AM Re: Floating Point - Should this simple expression work ?
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
And what would be the problem to convert all "partial" results to the "biggest" resolution type?

Let me explain a little better:

Int Op Int -> Evaluated as Int and result as Int;
Flt Op Flt -> Evaluated as Flt and result as Flt;
Int Op Flt -> Evaluated as Flt and result as Flt;
Flt Op Int -> Evaluated as Flt and result as Flt;

That is: whenever either the left or right operand's was a float, the expression would be evaluated in flot terms and the result saved as float.

That should probably not break compatibility in some 90+% old scripts. And a very strong emphasis on what to look for and fix regarding changes in expression evaluation on the readme file, would alert all those that have older scripts to go do a grep or something on their old files to find potential problems...

Just my two cents... [Smile]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70226 - 2002-09-30 10:13 AM Re: Floating Point - Should this simple expression work ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
There is not really any compelling reason to change the way it works at the moment.

The rules are simple and easy to follow, and of course without changing them they are backwards compatible in all cases [Smile]

Switching the rules to raising the expression to the highest type of the pair is not likely to reduce the number of times a cast (CINT(), CDBL(), CSTR(), VAL()) will be required to ensure that an expression will return the correct type, it just reduces the number of time it may be required for float expressions.

Strings will be particularly vulnerable. It is very common to append a numeric suffix to a string variable, such as
code:
$Filename=$Filename + $Sequence

Which will either cause $Filename to be converted to a numeric type with the type and value of $Sequence.

Of course the rule could apply to numeric types only, and not unassigned, string or other types. The drawback is this creates "special cases" - something to be avoided.

The string confusion could also be resolved by introducing an explicit catenate operator such as "." or ":". (Actually, I think that would be a good move anyway)

Casting both operators (and the result) to the highest type is not a bad thing, but it will break existing scripts, may complicate the rule and doesn't improve the KiXtart language.

Top
#70227 - 2002-09-30 01:11 PM Re: Floating Point - Should this simple expression work ?
Fernando Madruga Offline
Starting to like KiXtart

Registered: 2002-08-21
Posts: 149
Loc: Coimbra.Portugal.Europe.Earth....
Special cases are indeed more trouble, but that's more trouble once for the compiler/interpreter creator, as opposed to more trouble each and every time everyone uses some float expression.

Just my two cents though... Being a programmer, I tend to spend some time making things easier on the users, if that's something that a lot of people will use some time or some people will use a lot of time... [Smile]

{edit} Also, making KiXtart play according to some more "universal" rules, will only help people used to other languages to make the move to it... It also makes the code a lot easier to follow and to look back at a couple of months later if it's not "plagued" with CInts/CDbls, etc...

Surelly, there are some merits to not breaking compatability, but one should not stick to that and not see the world change and react accordingly... {/edit}

[ 30. September 2002, 13:18: Message edited by: Fernando Madruga ]
_________________________
Later,   [b]Mad[/b]ruga

Top
#70228 - 2002-09-30 01:54 PM Re: Floating Point - Should this simple expression work ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Currently, to ensure that an expression is evaluated as a float and returns a float one option would be:
code:
$floatResult=Cdbl($VariableA) opr $VariableB

You've coerced the first variable to a float so the rest of the expression will be a float.

If you change the rules so that the variables values are coerced to the higher type script writers will have to do things like
code:
$stringResult=$stringVariable + Cstr($Variable)

It's no better or worse really - you've just moved the requirement to cast/coerce the data type to a different situation.

Of course all this applies only where mixed types are in use. Where the variables in an expression have been declared or defined as the same type the problem never arises. If your float variables are initiated as 0.0, and your integers as 0 you won't have a problem in expressions unless you mix them. If you do mix them it is not unreasonable that you should cast them to the correct type for the expression.

The 'C' language does automatically convert operands to the higher of the types, but it it a strongly "typed" language where variable and function declarations have to include a type - and it doesn't have to deal with strings or unknown variable types.

Top
Page 2 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.071 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

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