Going Pass Limit of 64 bit Processor
-
/*I am doing calculations and I am noticing that sometimes the arithmetic goes pass the limit of the 64 bit processor without me even realizing it. The number simple start calculating again from zero(0). Is there some sort of argument or exception that can notify the user when a calculation violates the limit of the processor and continue to calculate from zero(0) again.*/
using System;
using System.IO;
using System.Collections;
namespace check
{
static class Program
{
static void Main(string[] args)
{
ulong increment = 2;
for (ulong i = 0; i < 70; i++)
{
increment += i * increment;
Console.WriteLine("{0}",increment);
}} }
}
-
/*I am doing calculations and I am noticing that sometimes the arithmetic goes pass the limit of the 64 bit processor without me even realizing it. The number simple start calculating again from zero(0). Is there some sort of argument or exception that can notify the user when a calculation violates the limit of the processor and continue to calculate from zero(0) again.*/
using System;
using System.IO;
using System.Collections;
namespace check
{
static class Program
{
static void Main(string[] args)
{
ulong increment = 2;
for (ulong i = 0; i < 70; i++)
{
increment += i * increment;
Console.WriteLine("{0}",increment);
}} }
}
Use
checked
Like in example bellow:
try { // The following line raises an exception because it is checked. z = checked(maxIntValue + 10); } catch (System.OverflowException e) { // The following line displays information about the error. Console.WriteLine("CHECKED and CAUGHT: " + e.ToString()); }
-
/*I am doing calculations and I am noticing that sometimes the arithmetic goes pass the limit of the 64 bit processor without me even realizing it. The number simple start calculating again from zero(0). Is there some sort of argument or exception that can notify the user when a calculation violates the limit of the processor and continue to calculate from zero(0) again.*/
using System;
using System.IO;
using System.Collections;
namespace check
{
static class Program
{
static void Main(string[] args)
{
ulong increment = 2;
for (ulong i = 0; i < 70; i++)
{
increment += i * increment;
Console.WriteLine("{0}",increment);
}} }
}
See here: checked (C# Reference)[^] Or you can enable it for the whole app: Go to project Properties and find the Build tab. Click "Advanced" button. In the resulting dialog, check the “Check for arithmetic overflow/underflow” box, and press OK.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Use
checked
Like in example bellow:
try { // The following line raises an exception because it is checked. z = checked(maxIntValue + 10); } catch (System.OverflowException e) { // The following line displays information about the error. Console.WriteLine("CHECKED and CAUGHT: " + e.ToString()); }
Where does the "e" comes from. What does "e" mean?
-
Where does the "e" comes from. What does "e" mean?
Look at type
catch (System.OverflowException e)
{ ...e is my variable name it is short for exception. It is not obligatory to use any name if you wanna catch OverflowException without more information.