Skip to main content
A double in Dart is a 64-bit (double-precision) floating-point number, as specified by the IEEE 754 standard. It is a concrete implementation of the abstract num class and represents fractional values or integers too large to be represented by the 64-bit signed int type.

Underlying Representation

The double type conforms to the binary64 format. The 64 bits are allocated as follows:
  • 1 bit: Sign
  • 11 bits: Exponent
  • 52 bits: Significand (Mantissa)
This structure provides approximately 15 to 17 significant decimal digits of precision.

Syntax and Literals

Double literals are defined by including a decimal point or by using an exponent. Since Dart 2.1, integer literals are automatically converted to double when used in a context where a double is expected.
// Standard decimal notation
double standard = 10.5;

// Scientific notation (1.42 x 10^5)
double scientific = 1.42e5; 

// Implicit conversion (integer literal assigned to double type)
double implicit = 10; // Becomes 10.0

Special Values

The double class supports specific constants defined by the IEEE 754 standard to handle arithmetic exceptions and limits.
  • NaN (Not a Number): Result of undefined operations (e.g., 0.0 / 0.0).
  • Infinity: Result of overflow or division by zero (e.g., 1.0 / 0.0).
  • Negative Infinity: Result of negative overflow or division by negative zero (e.g., -1.0 / 0.0).
double notANumber = double.nan;
double positiveInf = double.infinity;
double negativeInf = double.negativeInfinity;

// Verification properties
print(notANumber.isNaN);       // true
print(positiveInf.isInfinite); // true
print(standard.isFinite);      // true

Arithmetic and Division

While the num class defines basic operators (+, -, *), the division operator / in Dart always results in a double, even if both operands are integers.
var result = 5 / 2; 
print(result.runtimeType); // double
print(result);             // 2.5

Equality and Precision

Due to the binary approximation of decimal fractions, floating-point arithmetic may yield representation errors. Equality checks should account for precision loss. NaN Equality: According to IEEE 754, NaN is not equal to any value, including itself.
// Floating point representation error
double x = 0.1 + 0.2;
print(x == 0.3); // false (x is actually 0.30000000000000004)

// NaN comparison
print(double.nan == double.nan); // false

Platform Implementation

  • Dart Native (VM/AOT): Maps directly to the hardware’s 64-bit floating-point processor instructions.
  • Dart Web: Compiles to JavaScript Number. Since JavaScript numbers are also IEEE 754 doubles, the behavior is generally consistent, though bitwise operations may force truncation to 32-bit integers.
Master Dart with Deep Grasping Methodology!Learn More