[futurebasic] RE: [FB] divide 3 ways

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2008 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Fri, 4 Apr 2008 14:21:53 -0400
Never mind.  I see what happened.
Interestingly enough, something at my \ \ symbols


W. 

-----Original Message-----
From: Edwards, Waverly [mailto:Waverly.Edwards@...] 
Sent: Friday, April 04, 2008 1:52 PM
To: futurebasic@...
Subject: RE: [FB] divide 3 ways

If I recall correctly, just as you stated '\', '/' are synonymous.
The only difference in division was the '\' which was to bring about a integer result always.  I think  a couple years ago there was a vigorous debate about the behavior of '\'.  I think it would be great if we could collapse the '\' and '/' and get consistency on '\'.


W. 

-----Original Message-----
From: Robert Purves [mailto:listrp@...]
Sent: Sunday, March 30, 2008 9:59 PM
To: futurebasic@...
Subject: [FB] divide 3 ways


FB is uniquely aberrant among programming languages in having three symbols '/'  '\'  and '\' for the division operator.
In nearly all circumstances the symbols appear to be synonyms. You get the same result from all three. It doesn't seem to matter which you pick.
'----------------
dim as double y1, y2, y3
y1 = 1/3 : y2 = 1 : y3 = 1
print y1, y2, y3
y1 = 2/3 + 2/3 : y2 = 2 + 2 : y3 = 2 + 2 print y1, y2, y3

dim as long x1, x2, x3
x1 = 1/3 : x2 = 1 : x3 = 1
print x1, x2, x3
stop
'----------------


In rare circumstances that I take care to avoid in my own code the division symbol *does* matter. This example prints a 1 and two 0s, not necessarily in that order.
'----------------
dim as long foo, bar, var
foo = 2/3 + 2/3 : bar = 2 + 2 : var = 2 + 2 print foo, bar, var stop
'----------------

Suppose that you have code like that above, you Really Truly™ want the result of the addition to be 1, and you want others running your source to get 1 also. How can you ensure that? Should you use foo, bar or var?

Obviously var is no good. The '\' operator means that the division is done on the integer unit (see Appendix) so that both terms and their sum are 0.

The choice lies between foo and bar. A ridiculous fact is that you can't determine the values of foo or bar from inspecting the code. The value depends also on a checkbox in your preference settings:
   (FB)     [x] Use "\" for floating-point division
(FBtoC)    [x] \ forces floating division

I regard the existence of this checkbox as Insanely Stupid, and intend  
to remove it from FBtoC. †   The effect of the proposed change will be  
that '/' and '\' become synonyms, as they are now with FBtoC's default settings. In the second example above, foo will always be 0 and bar always 1.

Most FB projects will be completely unaffected by the change. FBtoC, to take one moderately complicated example, runs identically when built with the checkbox ON and OFF.

† unless dissuaded by reasoned advocacy or ignorant tirades

Robert P.

Appendix
Divisions are done on either the CPU's integer unit or its floating- point unit
1/3     ---integer-unit---> 0
7/4     ---integer-unit---> 1
1.0/3.0 --------fpu-------> 0.3333333...
7.0/4.0 --------fpu-------> 1.75

--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...

--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...