A practical example demonstrating all four related floating-point error configuration methods.

ID: 410

				
					using uCalcSoftware;

var uc = new uCalc();
Console.WriteLine($"Divide by Zero (Default): {uc.EvalStr("1/0")}");
uc.Error.TrapOnDivideByZero = true;
Console.WriteLine($"Divide by Zero (Error Enabled): {uc.EvalStr("1/0")}");

Console.WriteLine("");
Console.WriteLine($"Invalid Operation (Default): {uc.EvalStr("Sqrt(-1)")}");
uc.Error.TrapOnInvalid = true;
Console.WriteLine($"Invalid Operation (Error Enabled): {uc.EvalStr("Sqrt(-1)")}");

Console.WriteLine("");
Console.WriteLine($"Overflow (Default): {uc.EvalStr("5*10^308")}");
uc.Error.TrapOnOverflow = true;
Console.WriteLine($"Overflow (Error Enabled): {uc.EvalStr("5*10^308")}");

Console.WriteLine("");
Console.WriteLine($"Underflow (Default): {uc.EvalStr("10^-308/10000")}");
uc.Error.TrapOnUnderflow = true;
Console.WriteLine($"Underflow (Error Enabled): {uc.EvalStr("10^-308/10000")}");
				
			
Divide by Zero (Default): inf
Divide by Zero (Error Enabled): Division by 0

Invalid Operation (Default): nan
Invalid Operation (Error Enabled): Invalid operation

Overflow (Default): inf
Overflow (Error Enabled): Floating point overflow

Underflow (Default): 0
Underflow (Error Enabled): Floating point underflow
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   cout << "Divide by Zero (Default): " << uc.EvalStr("1/0") << endl;
   uc.Error().TrapOnDivideByZero(true);
   cout << "Divide by Zero (Error Enabled): " << uc.EvalStr("1/0") << endl;

   cout << "" << endl;
   cout << "Invalid Operation (Default): " << uc.EvalStr("Sqrt(-1)") << endl;
   uc.Error().TrapOnInvalid(true);
   cout << "Invalid Operation (Error Enabled): " << uc.EvalStr("Sqrt(-1)") << endl;

   cout << "" << endl;
   cout << "Overflow (Default): " << uc.EvalStr("5*10^308") << endl;
   uc.Error().TrapOnOverflow(true);
   cout << "Overflow (Error Enabled): " << uc.EvalStr("5*10^308") << endl;

   cout << "" << endl;
   cout << "Underflow (Default): " << uc.EvalStr("10^-308/10000") << endl;
   uc.Error().TrapOnUnderflow(true);
   cout << "Underflow (Error Enabled): " << uc.EvalStr("10^-308/10000") << endl;
}
				
			
Divide by Zero (Default): inf
Divide by Zero (Error Enabled): Division by 0

Invalid Operation (Default): nan
Invalid Operation (Error Enabled): Invalid operation

Overflow (Default): inf
Overflow (Error Enabled): Floating point overflow

Underflow (Default): 0
Underflow (Error Enabled): Floating point underflow
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Console.WriteLine($"Divide by Zero (Default): {uc.EvalStr("1/0")}")
      uc.Error.TrapOnDivideByZero = true
      Console.WriteLine($"Divide by Zero (Error Enabled): {uc.EvalStr("1/0")}")
      
      Console.WriteLine("")
      Console.WriteLine($"Invalid Operation (Default): {uc.EvalStr("Sqrt(-1)")}")
      uc.Error.TrapOnInvalid = true
      Console.WriteLine($"Invalid Operation (Error Enabled): {uc.EvalStr("Sqrt(-1)")}")
      
      Console.WriteLine("")
      Console.WriteLine($"Overflow (Default): {uc.EvalStr("5*10^308")}")
      uc.Error.TrapOnOverflow = true
      Console.WriteLine($"Overflow (Error Enabled): {uc.EvalStr("5*10^308")}")
      
      Console.WriteLine("")
      Console.WriteLine($"Underflow (Default): {uc.EvalStr("10^-308/10000")}")
      uc.Error.TrapOnUnderflow = true
      Console.WriteLine($"Underflow (Error Enabled): {uc.EvalStr("10^-308/10000")}")
   End Sub
End Module
				
			
Divide by Zero (Default): inf
Divide by Zero (Error Enabled): Division by 0

Invalid Operation (Default): nan
Invalid Operation (Error Enabled): Invalid operation

Overflow (Default): inf
Overflow (Error Enabled): Floating point overflow

Underflow (Default): 0
Underflow (Error Enabled): Floating point underflow