Internal Test: Verifies that only the division by zero flag is affected, while other floating-point exceptions like overflow remain unchanged by default.
ID: 405
using uCalcSoftware;
var uc = new uCalc();
// Enable only the division by zero error
uc.Error.TrapOnDivideByZero = true;
// This should now raise a uCalc error
Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}");
// This should still return 'inf' by default, as we didn't enable overflow errors
Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}");
// For comparison, enable overflow errors as well
uc.Error.TrapOnOverflow = true;
Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}");
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow using uCalcSoftware; var uc = new uCalc(); // Enable only the division by zero error uc.Error.TrapOnDivideByZero = true; // This should now raise a uCalc error Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}"); // This should still return 'inf' by default, as we didn't enable overflow errors Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}"); // For comparison, enable overflow errors as well uc.Error.TrapOnOverflow = true; Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Enable only the division by zero error
uc.Error().TrapOnDivideByZero(true);
// This should now raise a uCalc error
cout << "Test 1 (Div by Zero): " << uc.EvalStr("1/0") << endl;
// This should still return 'inf' by default, as we didn't enable overflow errors
cout << "Test 2 (Overflow): " << uc.EvalStr("1e308 * 2") << endl;
// For comparison, enable overflow errors as well
uc.Error().TrapOnOverflow(true);
cout << "Test 3 (Overflow with error): " << uc.EvalStr("1e308 * 2") << endl;
}
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Enable only the division by zero error uc.Error().TrapOnDivideByZero(true); // This should now raise a uCalc error cout << "Test 1 (Div by Zero): " << uc.EvalStr("1/0") << endl; // This should still return 'inf' by default, as we didn't enable overflow errors cout << "Test 2 (Overflow): " << uc.EvalStr("1e308 * 2") << endl; // For comparison, enable overflow errors as well uc.Error().TrapOnOverflow(true); cout << "Test 3 (Overflow with error): " << uc.EvalStr("1e308 * 2") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Enable only the division by zero error
uc.Error.TrapOnDivideByZero = true
'// This should now raise a uCalc error
Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}")
'// This should still return 'inf' by default, as we didn't enable overflow errors
Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}")
'// For comparison, enable overflow errors as well
uc.Error.TrapOnOverflow = true
Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}")
End Sub
End Module
Test 1 (Div by Zero): Division by 0
Test 2 (Overflow): inf
Test 3 (Overflow with error): Floating point overflow Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Enable only the division by zero error uc.Error.TrapOnDivideByZero = true '// This should now raise a uCalc error Console.WriteLine($"Test 1 (Div by Zero): {uc.EvalStr("1/0")}") '// This should still return 'inf' by default, as we didn't enable overflow errors Console.WriteLine($"Test 2 (Overflow): {uc.EvalStr("1e308 * 2")}") '// For comparison, enable overflow errors as well uc.Error.TrapOnOverflow = true Console.WriteLine($"Test 3 (Overflow with error): {uc.EvalStr("1e308 * 2")}") End Sub End Module