Le funzioni matematiche possono portare a errori critici in esecuzione.
Le funzioni a rischio possono essere messe in sicurezza controllando in anticipo i valori dei loro operandi.
TextWindow.WriteLine("------------------------------------------------------")
TextWindow.WriteLine("--- Funzioni matematiche SICURE --------------------")
TextWindow.WriteLine("------------------------------------------------------")
TextWindow.Write("Primo numero: ")
n1=TextWindow.ReadNumber()
TextWindow.Write("Secondo numero: ")
n2=TextWindow.ReadNumber()
TextWindow.WriteLine("------------------------------------------------------")
r=Math.Abs(n1)
TextWindow.WriteLine("Abs() - Valore assoluto = " + r)
If n1 > 1 Then
r=Math.GetRandomNumber(n1)
TextWindow.WriteLine("GetRandomNumber() - Numero casuale = " + r)
EndIf
r=Math.Max(n1,n2)
TextWindow.WriteLine("Max() - Massimo = " + r)
r=Math.Min(n1,n2)
TextWindow.WriteLine("Min() - Minimo = " + r)
r=Math.Pi
TextWindow.WriteLine("Pi - Pi greco = " + r)
r=Math.Power(n1,n2)
TextWindow.WriteLine("Power() - Potenza = " + r)
If n2 <> 0 Then
r=Math.Remainder(n1,n2)
TextWindow.WriteLine("Remainder() - Resto = " + r)
EndIf
If n1 >= 0 Then
r=Math.SquareRoot(n1)
TextWindow.WriteLine("SquareRoot() - Radice quadrata = " + r)
EndIf
TextWindow.WriteLine("------------------------------------------------------")
Anche la potenza può dare un errore critico…