typelevel/spire

Error in rational.toDouble

Open

#660 geöffnet am 21. Dez. 2017

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Scala (238 Forks)batch import
bughelp wantedlow hanging fruit

Repository-Metriken

Stars
 (1.775 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

The toDouble method on Rational instances returns incorrectly for certain inputs. To reproduce,

import spire.math.Rational

def bld(numStr: String, denomStr: String): (Double, Double) = {
  val num = BigInt(numStr)
  val denom = BigInt(denomStr)

  val expected = (BigDecimal(num) / BigDecimal(denom)).toDouble
  val actual = Rational(num, denom).toDouble

  (expected, actual)
}

println(
  bld(
    "179709322496314735297382168733437804616092100361307360024524978382010425322923559",
    "179709322496314735297382168733483632988275016201074155389238170380281177201180672"
  ))
println(
  bld(
    "-1257965257474203147081675181125850088132776039278857905825424935347911159685302509",
    "1257965257474203147081675181134385430917925113407519087724667192661968240408264704"
  ))
println(bld(
  "3618502788666131106986593281458997943466459808578940660043329292438660832363",
  "3618502788666131106986593281521497120414687020801267626233049500247285301248"
))

spire version: 0.14.1 scala version: 2.12.4 javac: 1.8.0_152 jvm: Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode) OS: Ubuntu 16.04

Contributor Guide