更多浮点数替代方案
More Floating Point Alternatives

原始链接: https://wizardzines.com/comics/floating-point-alternatives/

相比于标准二进制浮点数,基于软件的替代方案能够提供更高的精度或特定的实用功能,但由于缺乏硬件加速,其运行速度通常较慢。主要的替代方案包括: * **十进制浮点数:** 使用 10 进制而非 2 进制,以避免二进制舍入误差(例如 Python 的 `decimal`、Java 的 `BigDecimal`)。 * **分数:** 实现精确的有理数运算,确保 1/10 + 2/10 的计算结果精确等于 3/10。 * **符号计算:** 以精确的代数形式(如 $\sqrt{2}$)而非十进制近似值来保存数字,常用于 Mathematica 或 SymPy 等系统。 * **区间算术:** 将数字存储为范围,以追踪整个计算过程中的不确定性和误差界限。 * **二进码十进数 (BCD):** 一种主要见于旧式大型机系统和特定金融交易格式的传统编码方法。 尽管这些方法解决了特定的精度或表示问题,但由于性能上的权衡,它们更适合专门的应用场景,而非通用的高速计算。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 工作 | 提交 登录 更多浮点数替代方案 ( wizardzines.com ) 6 点 由 vismit2000 1 小时前 | 隐藏 | 过往 | 收藏 | 3 条评论 帮助 MiroslavPokorny 33 分钟前 | 下一条 [–] 奇怪的是,最明显的定点数竟然没有被提及。 回复 vismit2000 33 分钟前 | 父级 | 下一条 [–] https://wizardzines.com/comics/fixed-point/ 回复 schiffern 33 分钟前 | 上一条 [–] 虽然不是十进制格式,但业余计算语言 Frink 支持精确有理分数、任意宽度大整数(图中未展示)、区间算术和符号表达式。 https://frinklang.org/fsp/frink.fsp?fromVal=new+interval%5B-... 回复 准则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

more floating point alternatives

there are many alternative ways to represent numbers

These are all implemented in software (not hardware) so they’re a lot slower, and different languages have different libraries.

alternative 1: decimal floating point

This is like regular floating point, but in base 10 instead of base 2. It’s also standardized in IEEE 754.

Examples: Python’s decimal module or Java’s BigDecimal

alternative 2: fractions

This lets you do exact calculations with fractions (1/10 + 2/10 = 3/10)

Examples: Python’s fractions module in the standard library, Lisps have first-class support

alternative 3: symbolic computation

For example, sqrt(2) instead of 1.414.

You’ll see this in computer algebra systems like Mathematica, Maple, or sympy.

alternative 4: interval arithmetic

The idea is to store every number as a range so that you can precisely track your error bars.

Probably the least mainstream of these alternatives.

alternative 5: binary-coded decimal

This is how floating point numbers (and integers) were stored on IBM computers in the 60s, and you can still occasionally see it today in old formats like ISO 8583 for financial transactions.

联系我们 contact @ memedata.com