The getter and setter functionality for a single flag.
ID: 348
using uCalcSoftware;
var uc = new uCalc();
// Get the initial state (default is 0, no errors raised)
Console.WriteLine($"Initial flags: {uc.Error.FloatingPointErrorsToTrap}");
// Enable raising an error for division by zero
uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatDivisionByZero;
// Verify the new state
Console.WriteLine($"Updated flags: {uc.Error.FloatingPointErrorsToTrap}");
// Test the behavior
Console.WriteLine($"1/0 = {uc.EvalStr("1/0")}");
// Disable the flag by setting it back to 0
uc.Error.FloatingPointErrorsToTrap = 0;
Console.WriteLine($"Flags after reset: {uc.Error.FloatingPointErrorsToTrap}");
Console.WriteLine($"1/0 after reset = {uc.EvalStr("1/0")}");
Initial flags: 0
Updated flags: 8
1/0 = Division by 0
Flags after reset: 0
1/0 after reset = inf using uCalcSoftware; var uc = new uCalc(); // Get the initial state (default is 0, no errors raised) Console.WriteLine($"Initial flags: {uc.Error.FloatingPointErrorsToTrap}"); // Enable raising an error for division by zero uc.Error.FloatingPointErrorsToTrap = (int)ErrorCode.FloatDivisionByZero; // Verify the new state Console.WriteLine($"Updated flags: {uc.Error.FloatingPointErrorsToTrap}"); // Test the behavior Console.WriteLine($"1/0 = {uc.EvalStr("1/0")}"); // Disable the flag by setting it back to 0 uc.Error.FloatingPointErrorsToTrap = 0; Console.WriteLine($"Flags after reset: {uc.Error.FloatingPointErrorsToTrap}"); Console.WriteLine($"1/0 after reset = {uc.EvalStr("1/0")}");
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Get the initial state (default is 0, no errors raised)
cout << "Initial flags: " << uc.Error().FloatingPointErrorsToTrap() << endl;
// Enable raising an error for division by zero
uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatDivisionByZero);
// Verify the new state
cout << "Updated flags: " << uc.Error().FloatingPointErrorsToTrap() << endl;
// Test the behavior
cout << "1/0 = " << uc.EvalStr("1/0") << endl;
// Disable the flag by setting it back to 0
uc.Error().FloatingPointErrorsToTrap(0);
cout << "Flags after reset: " << uc.Error().FloatingPointErrorsToTrap() << endl;
cout << "1/0 after reset = " << uc.EvalStr("1/0") << endl;
}
Initial flags: 0
Updated flags: 8
1/0 = Division by 0
Flags after reset: 0
1/0 after reset = inf #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Get the initial state (default is 0, no errors raised) cout << "Initial flags: " << uc.Error().FloatingPointErrorsToTrap() << endl; // Enable raising an error for division by zero uc.Error().FloatingPointErrorsToTrap((int)ErrorCode::FloatDivisionByZero); // Verify the new state cout << "Updated flags: " << uc.Error().FloatingPointErrorsToTrap() << endl; // Test the behavior cout << "1/0 = " << uc.EvalStr("1/0") << endl; // Disable the flag by setting it back to 0 uc.Error().FloatingPointErrorsToTrap(0); cout << "Flags after reset: " << uc.Error().FloatingPointErrorsToTrap() << endl; cout << "1/0 after reset = " << uc.EvalStr("1/0") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Get the initial state (default is 0, no errors raised)
Console.WriteLine($"Initial flags: {uc.Error.FloatingPointErrorsToTrap}")
'// Enable raising an error for division by zero
uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatDivisionByZero)
'// Verify the new state
Console.WriteLine($"Updated flags: {uc.Error.FloatingPointErrorsToTrap}")
'// Test the behavior
Console.WriteLine($"1/0 = {uc.EvalStr("1/0")}")
'// Disable the flag by setting it back to 0
uc.Error.FloatingPointErrorsToTrap = 0
Console.WriteLine($"Flags after reset: {uc.Error.FloatingPointErrorsToTrap}")
Console.WriteLine($"1/0 after reset = {uc.EvalStr("1/0")}")
End Sub
End Module
Initial flags: 0
Updated flags: 8
1/0 = Division by 0
Flags after reset: 0
1/0 after reset = inf Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Get the initial state (default is 0, no errors raised) Console.WriteLine($"Initial flags: {uc.Error.FloatingPointErrorsToTrap}") '// Enable raising an error for division by zero uc.Error.FloatingPointErrorsToTrap = CInt(ErrorCode.FloatDivisionByZero) '// Verify the new state Console.WriteLine($"Updated flags: {uc.Error.FloatingPointErrorsToTrap}") '// Test the behavior Console.WriteLine($"1/0 = {uc.EvalStr("1/0")}") '// Disable the flag by setting it back to 0 uc.Error.FloatingPointErrorsToTrap = 0 Console.WriteLine($"Flags after reset: {uc.Error.FloatingPointErrorsToTrap}") Console.WriteLine($"1/0 after reset = {uc.EvalStr("1/0")}") End Sub End Module