Hi people,
i work on some example with very big score (number). The double type is not enough large to store the results. Can i create some variable type and set variable scope, or what to do? tnx

Dani AI

Generated

Quick clarification and practical options for the scenario described by @csharp: variable scope controls where and how long a variable exists, not how many digits it can hold. The right way to handle very large numeric values is to pick a numeric representation that supports the needed magnitude or precision. 's point about range vs precision is the key first step: decide whether an integer range or high-precision fractional arithmetic is required. 's advice about using wider built-ins only helps if the needed size fits those limits, and 's pointer toward library implementations is useful when it does not.

Python notes and examples. Python 3’s integer type already supports arbitrary precision; for fixed-point or decimal rounding control the decimal module is appropriate. Example usage:

# Python 3: arbitrary-size integer
n = 10**1000
print(type(n), n.bit_length())

# high-precision decimal
from decimal import Decimal, getcontext
getcontext().prec = 80
x = Decimal(1) / Decimal(7)
print(x)

See the Python Decimal documentation for details: Python decimal docs.

C++ options and example. Standard C++ has fixed-width built-ins only. For arbitrary-size integers, use Boost.Multiprecision’s cpp_int or link against GMP/MPIR for performance; for high-precision reals consider MPFR or Boost’s decimal backends. Minimal example with Boost.Multiprecision:

#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

using boost::multiprecision::cpp_int;

int main() {
    cpp_int big = 1;
    for (int i = 0; i < 1000; ++i) big *= 10;
    std::cout << big << '\n';
}

See Boost Multiprecision docs for usage and performance notes: .

Practical tips: large-number arithmetic is slower and memory-hungry; store values as strings or binary blobs if a DB must persist them; use fixed-point or scaled integers when fractional precision is bounded; for extremely large scores consider representing magnitude as mantissa+exponent to save space and speed. Test with representative sizes to confirm performance and storage trade-offs before committing to a library.

Recommended Answers

All 3 Replies

Double has a very very large range, what exactly is your range requirement? Or are you confusing range and precision?

Did you try "long" ?

Because it can take 64 bit number

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.