表观F#/ BCL浮点错误 [英] Apparent F#/BCL floating point bug

查看:96
本文介绍了表观F#/ BCL浮点错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是在FSI:

> System.Math.Round(0.2916, 2);;
val it : float = 0.29
> it * 100.;;
val it : float = 29.0
> int it;;
val it : int = 28

的结果是一样的,无论我尝试 - 编译F#3.1 / .NET 4.0应用程序,FSI在Visual Studio 2013年和2015年,.NET小提琴,@fsibot ....

The result is the same everywhere I tried - a compiled F# 3.1/.NET 4.0 application, FSI in Visual Studio 2013 and 2015, .NET Fiddle, @fsibot....

当然,这是一个错误的地方,不是吗?这是怎么回事吗?

Surely this is a bug somewhere, isn't it? What's going on here?

推荐答案

您可以更改F#FSI pretty的像Matlab的格式长打印机

You can change the F# FSI Pretty Printer like Matlab "format long"

fsi.AddPrinter( fun (x:float) -> sprintf "%26.16e" x);;

FSI输出

FSI output

System.Math.Round( 0.2916, 2)   //  2.8999999999999998e-001

1./3.                           // 3.3333333333333331e-001

这篇关于表观F#/ BCL浮点错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆