none
division by zero in small basic RRS feed

  • Question

  • TextWindow.write(any number/0) returns 0(zero)

    TextWindow.Write(0/any number) returns 0(zero) again!

     

    Is this a problem?

    Monday, July 19, 2010 6:47 PM

Answers

  • The second is obviously correct, the issue is the x/0.  Obviously this doesn't exist and in most languagues would cause an exception (crash). Other common excptions are:

    TextWindow.WriteLine(Math.ArcCos(2.0))
    TextWindow.WriteLine(Math.Power(-1.0,0.5))

    Both of these casue a crash in SmallBasic, perhaps x/0 should too.

    Either way, it is generally up the the programmer to prevent 'impossible' arithmetic - the outcome will be unpredictable at best and a crash at worst.

    If (x = 0) Then
      'Exception handling
    Else
      y = 1/x
    EndIf
    Monday, July 19, 2010 7:07 PM
    Moderator

All replies

  • The second is obviously correct, the issue is the x/0.  Obviously this doesn't exist and in most languagues would cause an exception (crash). Other common excptions are:

    TextWindow.WriteLine(Math.ArcCos(2.0))
    TextWindow.WriteLine(Math.Power(-1.0,0.5))

    Both of these casue a crash in SmallBasic, perhaps x/0 should too.

    Either way, it is generally up the the programmer to prevent 'impossible' arithmetic - the outcome will be unpredictable at best and a crash at worst.

    If (x = 0) Then
      'Exception handling
    Else
      y = 1/x
    EndIf
    Monday, July 19, 2010 7:07 PM
    Moderator
  • I fix those Math crash problems to my MathPlus Object. Now my functions returns "FAILED" if they Fail.

    Sorry My Bad English
    Wednesday, July 21, 2010 9:55 AM