Numeric Types - Squeng/Polyglot GitHub Wiki
Scala has numeric types Byte
, Short
, Int
, Long
, Float
, and Double
. Furthermore, the standard library features BigInt
and BigDecimal
.
Java has numeric types byte
, Byte
, short
, Short
, int
(yes, not integer), Integer
(yes, not Int), long
, Long
, float
, Float
, double
, and Double
. Furthermore, the standard library features BigInteger
(yes, not BigInt) and BigDecimal
.
Python has numeric types int
, float
, and complex
. Furthermore, the standard library features Decimal
and Fraction
.
Python's int
, Java's BigInteger
, and Scala's BigInt
are arbitrary-precision integers (well, limited by memory space).
Python's float
corresponds to Java's double
/Double
and Scala's Double
in that it's an IEEE 754 64-bit floating-point number.
Scala's types correspond to Java's primitive types in that they are non-nullable value types that are mapped to primitive types behind the scenes (in the Scala type hiearchy, they are actually in a different branch than the reference types / java.lang.Object
descendants, which—by the way—could be made non-nullable as well). Caveat:
var i = 123456789
var d = 123456789.0
println(i) // 123456789
println(d) // 1.23456789E8
// i = null <- would be a compile-time error
// d = null <- would be a compile-time error
// but ...
val in = null.asInstanceOf[Int]
val dn = null.asInstanceOf[Double]
// ... is not a compile-time error
println(in) // 0
println(dn) // 0.0