D
D
dark_spectator2018-12-05 08:22:59
C++ / C#
dark_spectator, 2018-12-05 08:22:59

How to store and perform operations on a large number of type int?

There is a type variable decimal; it has its own limit and at some point, when subtracting a smaller number, it goes into a negative value. Is there any other way to store a very large integer and perform mathematical operations on it. I'm new to Unity and C#, if it's not difficult, tell me more. If you need sources, write, I will share.
Number example:
91948102834320102834715231012347
This is the maximum value.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2018-12-05
@EreminD

the easiest option is to use BigInteger

using System;
using System.Numerics;
          
public class Program
{
  public static void Main()
  {
    BigInteger hugeInt = BigInteger.Parse("91948102834320102834715231012347");
    Console.WriteLine(hugeInt);
  }
}

But in general, there is a feeling that you will suffer more with extra data types.
And if it's not a secret, what do you store in such numbers? Are you doing some kind of arithmetic with them?

A
Alex Maximovich, 2018-12-05
@flexer1992

Alternatively, you can implement algorithms for working with long numbers yourself. A branch of computer science is called long arithmetic. brestprog.by/topics/longarithmetics

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question