# Divide by Zero -1.#INF error correction

## Recommended Posts

Hi,

Had some problems with a big statistical calculator I've been working on, in that after after a plethora of complicated math functions my number return was coming out as -1.#INF.....which after a search of the forum I learnt was due to a 'divide by zero' occurring somewhere in the script math.

The advice given in the forum to other people who had had this error was to set up code to check for this error BEFORE it occurred, e.g.:

```If Not \$divisor = 0 Then \$result = \$number / \$divisoroÝ÷ Ûbr¬{W§µ§oÇ¢~Ø^{^ÚÊjW.«b¢x¬·

\$result = 1 / 0

If _MathCheckDiv(\$result,1) = -1 Then \$result = "Divide by zero error"

MsgBox(0,"",\$result)```

I pass it on for what it's worth.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

##### Share on other sites

...also just realised that the error comes out as -1.#IND or 1.#INF

can't correct the above post - it keeps giving errors (? autoit /autoit wrappers ?)

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

##### Share on other sites

Hello,

I am not sure if I understand you correctly, but what about making

your own Div() function? You would have to replace parts of your formulas,

but can handle div/0 easily. Here is an example, its best to start it in SciTE,

to see the ConsoleWrite() output.

```ConsoleWrite('example 1'&@LF)
\$x = 10
\$y = 2
\$r = Div(\$x*\$x*3.141,\$y)
If @error Then
ConsoleWrite('division by zero error handling'&@LF)
Else
ConsoleWrite('result: '&\$r&@LF)
EndIf

ConsoleWrite('example 2'&@LF)
\$x = 10
\$y = 0
\$r = Div(\$x*\$x*3.141,\$y)
If @error Then
ConsoleWrite('division by zero error handling'&@LF)
Else
ConsoleWrite('result: '&\$r&@LF)
EndIf

Func Div(\$v1,\$v2)
If \$v2 = 0 Then Return SetError(1,0,0)
Return \$v1/\$v2
EndFunc```

ciao

Xandl

## Create an account

Register a new account