PyNum class final

Python-like number: can be either integer (BigInt) or float (double).

Provides Python-style numeric behavior, including arithmetic, comparison, bitwise operations (for integers), modulo, and power operations. This class aims to emulate Python's int and float behavior in Dart.

Implemented types

Constructors

PyNum(num v)
Creates a PyNum from a Dart num (either int or double). Throws ArgumentError for unsupported types.
factory
PyNum.bigInt(BigInt v)
Creates a PyNum from a Dart BigInt.
factory
PyNum.double(double v)
Creates a PyNum from a Dart double.
factory
PyNum.int(int v)
Creates a PyNum from a Dart int.
factory

Properties

doubleValue → double?
Returns the double value if this is a float, otherwise null.
no setter
hashCode → int
The hash code for this object.
no setteroverride
intValue → BigInt?
Returns the BigInt value if this is an integer, otherwise null.
no setter
isDouble → bool
check if number is double (python float)
no setter
isInt → bool
check if number is integer
no setter
isZero → bool
Returns true if the number equals zero. Works for both integers and floats.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

abs() → PyNum
Returns absolute value.
compareTo(PyNum other) → int
Compares this object to another object.
override
mod(PyNum other) → PyNum
Computes the modulo of this number by other, emulating Python's % behavior.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(PyNum exponent) → PyNum
Raises this number to the power of exponent. Preserves integer type if both base and exponent are integers.
toDouble() → double
Returns the numeric value as double, even if this number is an integer.
toString() → String
A string representation of this object.
override
valueEquals(PyNum other) → bool
Compares numeric values for equality. Handles Python-style integer/float comparisons.

Operators

operator &(PyNum other) → PyNum
Bitwise AND. Only valid for integers.
operator *(PyNum other) → PyNum
Multiplies two PyNums, returning a PyNum.
operator +(PyNum other) → PyNum
Adds two PyNums, returning a PyNum. Preserves integer type if both operands are integers.
operator -(PyNum other) → PyNum
Subtracts two PyNums, returning a PyNum.
operator /(PyNum other) → PyNum
Divides two PyNums, returning a float (double) result. Throws UnsupportedError on division by zero.
operator <(PyNum other) → bool
Returns true if this PyNum is less than other. Works for integers and floats. Automatically converts integers to double if one of the operands is a float, emulating Python comparison behavior.
operator <<(PyNum other) → PyNum
Bitwise left shift. Only valid for integers.
operator <=(PyNum other) → bool
Returns true if this PyNum is less than or equal to other. Works for integers and floats. Automatically converts integers to double if one of the operands is a float, emulating Python comparison behavior.
operator ==(Object other) → bool
Returns true if this PyNum is equal to other.
override
operator >(PyNum other) → bool
Returns true if this PyNum is greater than other. Works for integers and floats. Automatically converts integers to double if one of the operands is a float, emulating Python comparison behavior.
operator >=(PyNum other) → bool
Returns true if this PyNum is greater than or equal to other. Works for integers and floats. Automatically converts integers to double if one of the operands
operator >>(PyNum other) → PyNum
Bitwise right shift. Only valid for integers.
operator ^(PyNum other) → PyNum
Bitwise XOR. Only valid for integers.
operator unary-() → PyNum
Unary negation.
operator |(PyNum other) → PyNum
Bitwise OR. Only valid for integers.
operator ~() → PyNum
Bitwise NOT. Only valid for integers.
operator ~/(PyNum other) → PyNum
Performs integer division, similar to Python //. Returns BigInt if both operands are integers, otherwise returns float.