![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
unfiltered2.10対応しようとするも、dispatch-classisがでていないことに気づいて、dispatchいじってたらこのバグ https://t.co/bXmQQcSe のせいで、dispatchのテストが通らなくなってあばばばば。なんだよこのひどいバグ・・・
2012-12-21 15:11:12![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
Scala2.10.0.finalでは、BigDecimal のisValidDoubleとisValidFloatの動作および、BigDecimalとFloatやDoubleを比べたときの挙動が2.9.2と変わってるので気をつけてください。っていうか仕様はどうあるべきなのだろう
2012-12-21 15:16:19![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
Scala2.10.0.finalだとBigDecimal(0.5).isValidFloat、 BigDecimal(0.25).isValidFloatなど浮動小数点としてきりよく表せる場合はtrueで、BigDecimal(0.2).isValidFloatだとfalse
2012-12-21 15:19:53![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
BigIntのisValidLongも2.9のときバグってたし http://t.co/MGsbgIIX BigIntやBigDecimal使ってて、このあたり理解せずにScala2.9から2.10に上げると危険だし、ハマった場合に原因特定するのめんどくさそう・・・
2012-12-21 15:28:35![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
うええ。ふつう valid な double、っていうとdoubleとして正しいビット列、とかNaNじゃない、あたりじゃないかと思うんだけど。完全にdouble/floatに変換できるか、ならcanDoubleとかにすべきなんじゃ。
2012-12-21 15:52:22![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
.@yasushia あ、最初自分は「NaNやInfinityでない場合はtrue返すように実装したつもりがバグった」のかと思ってましたが、コメント https://t.co/tTp8cOlo みると意図した仕様なんですかね・・・?でもissueはopenのままだし謎
2012-12-21 15:59:08![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@xuwei_k BigDecimal.isValidInt が within the range of Int MinValue and MaxValue; otherwise returns false なんで意図した仕様だと思いますね。欲しい人はいないような気がしますが…
2012-12-21 16:02:32![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
.@yasushia でも、それをequalsで使っていることにより、Scala2.10.0においては、 BigDecimal(0.1) == 0.1はfalseで、BigDecimal(0.5) == 0.5はtrue になるという・・・(Scala2.9では両方true)
2012-12-21 16:05:40![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@xuwei_k あー。なるほど。やっと理解しました。Float/DoubleにMin/Maxがないから、その意図にすらなってないんですね。うーん。Javaのほう確認してみます
2012-12-21 16:09:12![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@yasushia @xuwei_k Java の方だと, Long, Double は -∞ < any value < ∞ < NaN という奇妙な全順序になってます. ところが Scala だと NaN は他の値とは比較できないようになってます.
2012-12-21 16:12:24![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@xuwei_k @yasushia あ, BigDecimal の話題でしたか. ズレてましたm(__)m
2012-12-21 16:17:01![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@cocoatomo @xuwei_k BitDecimal.isValidDoubleという関数が追加されていて、これの仕様が「正しくDoubleに変換できるBigDecimal値」という仕様のようなんですが、無限小数(0.1とか)は不正と判定してて、これなに?、という
2012-12-21 16:17:53![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
これが影響うけるのは、BigDecimalとDouble/Floatを比較してる場合、かなぁ。でもこのisValidDoubleがfalseになるような値だと結局==は失敗しそうだから、それほど影響ない?
2012-12-21 16:20:49![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@yasushia @cocoatomo まぁJavaのものを参考にするにしても、Scalaでは違うclassなわけで(javaのBigDecimalを継承してるわけじゃない) 必ずしも従う必要はないとは思いますが、とにかく仕様が曖昧でどの状態がバグなのかがわからなくてあれですね
2012-12-21 16:21:37![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@yasushia @xuwei_k あぁーなるほど. その「正しく Double」が Infinity, NaN 含むかどうかはあやしそうですね.
2012-12-21 16:21:44![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@cocoatomo @xuwei_k Infは排除してるみたいですね。ただ0.1もisValidDouble==falseなのは、なんかヘンな気がします
2012-12-21 16:25:12![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@yasushia @xuwei_k とすると, -∞ < any value < ∞ という判定をすればいいんじゃないかなぁ……
2012-12-21 16:28:29![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
@cocoatomo @xuwei_k ですね。ただ、toDoubleがJavaのdoubleValueをそのままつかっているので、その時点で範囲外はInfで返ってくるので、isValidDoubleは!isInfinityだけで十分そうです。
2012-12-21 16:35:22