Just for fun ;-) Well GF Don't get crazy again ... your Function has so many mistakes it's awful
First: all your results are integers - so why do you use num_A# and num_B# ? You give advice "Please stop complaining & make a function for it." And then provide a Function you have never tried ... otherwise you would have noticed how wrong the results are!
num_A can be 0 because you can devide 0 by any number not 0 (result is always 0) that makes If ( num_A# = 0 Or num_B# = 0 ) Then Return in your function wrong
the rest is complete false thinking. you cannot just swap a and b and expect to have a right result.
num_A / num_B is not the same as num_B / num_A it has nothing to do which of the numbers is bigger or smaller ... You just want to divide
Line 4 and Line 5 will never be reached - the function (in case it returns anything) is left after Line 2 or Line 3 anyway ...
Finally: You forgot what happens if both numbers are the same - your function provides 0 but it must be 1.0
Graphics 640, 580, 0, 2
Print "5.0 / 0.0 Not allowed"
Print "changed GF.function to give it a little bit of sense"
Print "GF_function now: "+check_Num(5.0, 0.0)
Print "Should return 4.65661e-010 as error code catching division by 0"
Print "GF_function original: "+GF_check_Num(5.0, 0.0)
Print "CheckZero_Div: "+CheckZero_Div(5.0, 0.0)
Print "------------"
Print "0.0 / 5.0"
Print 0.0 / 5.0
Print "GF_function: "+check_Num(0.0, 5.0)
Print "Should be 0.0 - shows Infinity because GF swaps number positions "
Print "GF_function original: "+GF_check_Num(0.0, 5.0)
Print "CheckZero_Div: "+CheckZero_Div(0.0, 5.0)
Print "------------"
Print "2.0 / 5.0"
Print 2.0 / 5.0
Print "GF_function: "+check_Num(2.0, 5.0)
Print "Should be 0.4"
Print "GF_function original: "+GF_check_Num(2.0, 5.0)
Print "CheckZero_Div: "+CheckZero_Div(2.0, 5.0)
Print "------------"
Print "5.0 / 2.0"
Print 5.0 / 2.0
Print "GF_function: "+check_Num(5.0, 2.0)
Print "Should be 2.5"
Print "GF_function original: "+GF_check_Num(5.0, 2.0)
Print "CheckZero_Div: "+CheckZero_Div(5.0, 2.0)
Print "------------"
Print "5.0 / 5.0"
Print 5.0 / 5.0
Print "GF_function: "+check_Num(5.0, 5.0)
Print "Should be 1.0"
Print "GF_function original: "+GF_check_Num(5.0, 5.0)
Print "CheckZero_Div: "+CheckZero_Div(5.0, 5.0)
Print "------------"
WaitKey()
End
; GuyFawkes Function - corrected missing # in Function name
Function Check_Num# ( num_A#, num_B# )
If ( num_B# = 0 ) Then Print "Line 1 - returns 4.65661e-010 as error code ": Return 1.0 / 9999999999999999999999999999999 ; just to show anything
If ( num_A# < num_B# ) Then Print "Line 2 - " : Return ( num_B# / num_A# )
If ( num_B# < num_A# ) Then Print "Line 3 - " : Return ( num_A# / num_B# )
If ( num_A# > num_B# ) Then Print "Line 4 - " : Return ( num_A# / num_B# )
If ( num_B# > num_A# ) Then Print "Line 5 - " : Return ( num_B# / num_A# )
End Function
Function GF_Check_Num ( num_A#, num_B# )
If ( num_A# = 0 Or num_B# = 0 ) Then Return
If ( num_A# < num_B# ) Then Return ( num_B# / num_A# )
If ( num_B# < num_A# ) Then Return ( num_A# / num_B# )
If ( num_A# > num_B# ) Then Return ( num_A# / num_B# )
If ( num_B# > num_A# ) Then Return ( num_B# / num_A# )
End Function
Function CheckZero_Div#(a#,b#)
If (b# = 0.0)
Return 999999.0*10^32 ; return a very high number
Else
Return (a# / b#)
EndIf
End Function
@Mimi You always check Variables in your code for 0.0 before you make divisions and your variable can be 0 Or in some cases catch infinity with a very high number
Function CheckZero_Div#(a#,b#)
If (b# = 0.0)
Return 999999.0*10^32 ; return a very high number
Else
Return (a# / b#)
EndIf
End Function
|