[futurebasic] Divide by Zero error

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2009 : Group Archive : Group : All Groups

From: Walter Lenk <Walter_Lenk@...>
Date: Sat, 6 Jun 2009 16:52:37 -0400
Greetings -

I recently wrote an app for a client and released it to him as a 
universal binary generated via FBtoC. The app tested fine on my PPC 
G5 iMac, but when the client ran it on his INTEL Mac Book, it crashed 
consistently. Also, the FB generated code ran fine on the client's 
Intel machine under Rosetta.

I think that I have traced one of the Intel crash problem to a 
division by zero error, and in doing so I had to investigate the ways 
that various combinations of machines and software handle this 
exception.

Here are the various combinations that I explored:
  1. FB generated code on a PPC Mac
  2. FB generated code on an Intel Mac under Rosetta
  3. FB2C generated PPC code on a PPC Mac
  4. FB2C generated PPC code on an Intel Mac under Rosetta
  5. FB2C generated INTEL code on an Intel Mac

I wrote a little program that tested the 3 various methods of 
division using the formula A = B / C, where B = 10, C = 0, and 
STR$(A) was printed to the screen. I compiled the program the 3 
different ways, and the PPC code was run on both machines, with the 
Intel code only being run on the Intel machine.

I tested this program on these 2 machines:
  a 2.1 GHz G5 iMac running OS 10.4.11
  a 1.66 GHz INTEL Core Duo Mac Mini running OS 10.5.7

The results were:
       Formula   FB PPC  FB2C PPC  FB2C INTEL
  1. A% = B%/C%       0         0   >CRASHES<
  2. A% = B%\C%  2^31-1        -1           0
  3. A# = B#/C#       0    ' inf'      ' inf'
    (A# = B#\C# -> same as above)

Note that the results for both the FB PPC version and the FB2C PPC 
version were the same irregardless of whether the version was running 
on a PPC machine or on an Intel machine under Rosetta - good job 
Apple!.

Although 10/0 is not defined and therefore best avoided, it would be 
great if the response to this programming blunder would be consistent 
- rather tan 4 different answers and a crash.

Comments ?

Best,

Walter

-- 

===========================================
Walter Lenk    Cambridge Ma    617-547-7781
===========================================