Jump to content

Divide by Zero -1.#INF error correction


andybiochem
 Share

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¬·
(®Økyébë(}Êxz0z÷«¶©®+jb0jÊn¶Ø§Ú zØ^®ém^~éܶ*'±©ezn¶Ø§Ú©`¢¸­l!ÈpjÆÚ±çZ®§u©Ú®¶²¡û(î´ÓMéÛZÂÊ.ÖÞ¦^ØدÊ+±¶¬yÚ'ºÇ«zn¶Æ§v)â±ëmx,"Ü(ºWaj÷yéÚâ âfj·­¢¯zÚç$z÷«ÊȧW¢µé×è®k¥iú+¶©¢×§¶&¥¡öøy¼³zº0iÉ(J!jÒ0j{^w¬k²¡ùh¢H§­~ííH4VÞx+zÛ«çZÛh­êeiÇ¢·­«¨µê뢺®¢Ú+ë-jw¦¦Ü¬¶¸§8^­íý²z-)àÞjyèÊ)àhh¶§he¢±1qé]¡Ë¦z{m¡·¥Û^­çpØu Ñ^®º+°z0z÷«¶¬v¬mÂäjëh×6If $result = "-1.#INF" then $result = ""oÝ÷ Ù©Ýè­êÝÖ§Êaz¼ÊëyÊ +"ayê뢸§r[x°Û¦mêÓìÈbv+^½éí¹©eˬjëh×6#include <Math.au3>

$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!
Link to comment
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!
Link to comment
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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...