binkley / kotlin-rational

An immutable, infinite-precision Rational (ratio, fraction) class for Kotlin
The Unlicense
12 stars 2 forks source link

Formatting of floating point #120

Open binkley opened 2 years ago

binkley commented 2 years ago

There are challenges when using BigDecimal and constructors such as BigDecimal(Double) vs BigDecimal(String). For example: BigDecimal(1.0) has different "scale" than BigDecimal("1.0")

Design & implement a consistent policy for FloatingBigRational. Options may include:

  1. Follow the patterns of BigDecimal
  2. Always show a decimal point to emphasize the floating-point nature, eg, "3.0 / 2.0" vs "3 / 2"

Present code leans towards the former (partly by accident).

binkley commented 2 years ago

Note that internally FloatingBigRational is still the ratio of two BigIntegers, not two BigDecimals. Option 2 would imply:

println(FixedBigRational.valueOf(2))
println(FloatingBigRational.valueOf(2))

prints:

3/2
3.0/2.0