Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Going Pass Limit of 64 bit Processor

Going Pass Limit of 64 bit Processor

Scheduled Pinned Locked Moved C#
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    computerpublic
    wrote on last edited by
    #1

    /*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);
    }

        }
    }
    

    }

    P OriginalGriffO 2 Replies Last reply
    0
    • C computerpublic

      /*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);
      }

          }
      }
      

      }

      P Offline
      P Offline
      Piotr Bagazja
      wrote on last edited by
      #2

      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());
          }
      

      checked on msdn

      C 1 Reply Last reply
      0
      • C computerpublic

        /*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);
        }

            }
        }
        

        }

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        See here: checked (C# Reference)[^] Or you can enable it for the whole app: Go to project Prop­er­ties and find the Build tab. Click "Advanced" button. In the resulting dialog, check the “Check for arith­metic 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 – ∞)

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • P Piotr Bagazja

          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());
              }
          

          checked on msdn

          C Offline
          C Offline
          computerpublic
          wrote on last edited by
          #4

          Where does the "e" comes from. What does "e" mean?

          P 1 Reply Last reply
          0
          • C computerpublic

            Where does the "e" comes from. What does "e" mean?

            P Offline
            P Offline
            Piotr Bagazja
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups