我想用C#制作Windows计算器,应使用哪种类型 [英] I would like to use c # to make the windows calculator, what type should be used

查看:49
本文介绍了我想用C#制作Windows计算器,应使用哪种类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我考虑使用双重检验,但似乎不是双重检验

由于Windows:2/3 = 0.66666666666666666666666666666667这样的窗口不能在double

I think of using double, but seemingly not the double test

As windows :2/3 = 0.66666666666666666666666666666667 like that can not be in the double

推荐答案

中,所以不能为double.有效位数太多.

没有任何英特尔浮点类型提供这种精度.
如果扩展类型提供了最好的精度,扩展类型是80位类型(双精度为64位),但是即使extended也支持大约19位尾数. .NET不支持此类型.

小型手计算器使用不同的实数模型和计算方式,称为逐位数字.
使用英特尔,可以通过更大的浮点类型的软件仿真来提供更高的精度.
我认为可以使用System.Numerics.BigInteger(仅在.NET Framework v.4中可用)开发这样做的基本方法.这不是一个非常简单的任务.


回答有关使用System.Numerics.BigInteger的想法的后续问题.
当然,这是一个现成的类,而不是其他类,仅用于支持无限精度的整数计算.这堂课很棒.

没有什么可以实现具有无限(或只是高但有限的精度)的浮点计算的计算模型.
我的想法不容易实现,需要付出巨大的努力,它比从头开始要好.您可以在结构中使用几个BigInteger字段,一个表示尾数,另一个表示指数字段(或10或2,取决于设计选择).您需要在此结构上定义一组操作,使用格式在字符串之间进行转换,等等.

您可以在此处找到有关如何表示模拟浮点执行计算的基本说明: http://en.wikipedia.org/wiki/Floating_point [ ^ ].

具有非标准精度(对于CPU)的要求非常少见,因此可能很难找到现有代码.也许在FPU很少见的情况下,某些代码可以从过去的代码继承而来.

同样,该问题可以解决,但并非易事.

作为一种简单的替代方法,可以将BigInteger用作固定精度的小数.这很简单.只需添加一个字段小数位数",然后使用整数进行所有计算.假定最终结果中小数点在适当的位置数处向左移动.

—SA
Sure, it cannot be double. Too many significant digits.

None of the Intel floating point types provide such precision.
The best precision if provided by the type extended, which is a 80-bit type (double is 64 bits), but even extended supports about 19 digits of mantissa. This type in not supported by .NET.

Small hand calculators use different model of real numbers and calculations called digit-by-digits.
With Intel, better precision can be provided by software simulation of bigger floating point type.
I think the base way of doing so can be developed using System.Numerics.BigInteger (only available in the .NET Framework v.4). This is not a very simple task.


Answering a follow-up question on my idea to use System.Numerics.BigInteger.
This is of course a ready-to-use class, not the different one, just to support integer calculations with unlimited precision. This class is just great.

There is nothing which would implement calculation model of floating-point calculation with unlimited (or just high but limited precision).
My idea is not easy to implement, will need essential effort, it just better than doing it from scratch. You can use a structure with couple of BigInteger fields in it, one representing mantissa, another one — the exponent field (or 10 or 2, depending on choice of design). You need to define set of operations on this structure, conversions from and to string using formats, etc.

You can find the basic directions on how to represent the emulated floating-point carry out calculations here: http://en.wikipedia.org/wiki/Floating_point[^].

The requirement of having non-standard precision (for the CPU) is very unusual, so it can be difficult to find existing codes. Maybe, some codes could be inherited from the old-days codes when FPU were rare.

Again, the problem is solvable, but not really easy.

As a simple alternative, you can use BigInteger as a fixed-precision fractional. This is very simple. Just add a field "number of decimal places" and do all calculation with integers. Assume in the final result the decimal point is moved to left on appropriate number of positions.

—SA


您可以通过google或bing获取"Calculator Precision"(计算器精度),以获得很多不错的结果.您可以从以下一些好的链接开始:

http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic [ http://support.microsoft.com/kb/125056 [ http://www.thimet.de/calccollection/Calc-Precision.html [ ^ ]

http://www.fractal-landscapes.co.uk/bigint.html [ ^ ]
You can google or bing for "Calculator Precision" to get lots of good results. Here are some good links that you can start with:

http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic[^]

http://support.microsoft.com/kb/125056[^]

http://www.thimet.de/calccollection/Calc-Precision.html[^]

http://www.fractal-landscapes.co.uk/bigint.html[^]


我的2ct的:
Math.Net项目 [ ^ ]

只要有空,为什么还要少买些东西:)

问候
Espen Harlinn
My 2ct''s:
Math.Net Project[^]

As long as it''s available, why settle for something less :)

Regards
Espen Harlinn


这篇关于我想用C#制作Windows计算器,应使用哪种类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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