简体   繁体   English

存储大量数字的好方法是什么? (例如572e6561)在C#中

[英]What's a good way to store extremely large numbers? (Eg. 572e6561) in C#

My first thought was to implement a class which stores the coefficient as a double, and the 10^X as an int/short. 我的第一个想法是实现一个将系数存储为双精度值并将10 ^ X存储为int / short的类。

I want to use engineering notation over scientific notation because it's simpler for end-users. 我想使用工程表示法而不是科学表示法,因为对于最终用户而言,它更简单。

If there are projects for doing this, I can't seem to find them. 如果有用于执行此操作的项目,我似乎找不到它们。

I know System.Numerics.BigInteger exists, but it's pretty slow. 我知道System.Numerics.BigInteger存在,但是速度很慢。 I really want high speed for performing many calculations on mobile devices. 我真的想在移动设备上执行许多计算时要有很高的速度。 I just want to store numbers as engineering notation. 我只想将数字存储为工程符号。

Any ideas? 有任何想法吗?

If you don't need a lot of precision, just large magnitudes, then I'd say use two values to represent mantissa and exponent. 如果您不需要很高的精度(仅大幅度),那么我想说两个值代表尾数和指数。 Using integers for both would be closer to how floating point numbers are handled internally. 两者都使用整数将更接近于内部如何处理浮点数。 But using floating point at least for the mantissa would probably make it easier to implement many of the operations, at the cost of a few bits of mantissa precision. 但是,至少对尾数使用浮点数可能会使得更容易实现许多操作,但要花费一些尾数精度。

C has functions like frexp and ldexp to separately deal with mantissa and exponent of a floating point number. C具有frexpldexp之类的功能 ,可分别处理尾数和浮点数的指数。 I don't know any C# or .NET, but perhaps similar functions are available there as well. 我不知道任何C#或.NET,但也许那里也有类似的功能。

If you use double for the exponent as well, you'd theoretically really big numbers. 如果您也对指数使用double,那么从理论上讲您将是一个很大的数字。 But if that exponent isn't exact, due to rounding, then you don't know the exponent at all, which makes the mantissa worthless. 但是,如果由于舍入而导致该指数不精确,那么您根本就不会知道该指数,这会使尾数一文不值。 So if you need numbers big enough to consider such things, you either need to use some big integer for the exponent, or can drop the mantissa completely and just express those big numbers as powers of two with an approximate exponent. 因此,如果您需要足够大的数字来考虑这样的事情,则要么需要对指数使用某个大整数,要么可以完全舍弃尾数,然后将这些大数字表示为具有近似指数的2的幂。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#项目中存储不变变量的好方法是什么? - What's a good way to store unchanging variables in a C# project? 存储大量静态数据的好方法是什么? - What's a good way to store large amounts of static data? C# - 用空格解析文件名的最简单方法,例如。 “C:\\ Test \\ File with spaces.txt” - C# - Easiest way to parse filename with spaces eg. “C:\Test\File with spaces.txt” 在C#中,什么是显示可缩放,可平移视频的好方法? - In C#, what's a good way for displaying zoomable, pannable video? 在C#中捕获StackOverflow异常的一般方法是什么? - What's a good general way of catching a StackOverflow exception in C#? 在C#中编写批处理脚本的好方法是什么? - What's a good way to write batch scripts in C#? 什么是大型C#/ C ++解决方案的良好目录结构? - What's a good directory structure for large C#/C++ solutions? 什么是提供一系列唯一数字(C#vs Sql)的好方法? - what is a good way to provide a range of unique numbers (C# vs Sql)? 在C#中通过网络发送大文件的好方法? - Good way to send a large file over a network in C#? C#代码语法中的“s”和“e”是什么 - what are “s” and “e” in C# code syntax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM