9个版本
0.4.3 | 2024年2月3日 |
---|---|
0.4.1 | 2023年12月17日 |
0.4.0 | 2023年9月12日 |
0.3.2 | 2023年3月4日 |
0.3.0 | 2022年11月10日 |
#567 in 数学
1,777 每月下载量
在 19 个crate中(直接使用4个) 使用
1MB
20K SLoC
dashu-float
作为dashu
库的一部分,实现任意精度的浮点数。有关完整文档,请参阅Docs.rs。
功能
- 支持
no_std
,并使用纯Rust编写。 - 支持任意基数和任意舍入模式。
- 支持高效的基数转换。
- 小浮点数在栈上内联。
- 以2~36为基数高效地进行浮点数的解析和打印。
- 支持C++使用的十六进制浮点数格式。
- 为浮点数提供开发者友好的调试打印。
可选依赖
std
(默认):为依赖项启用std
支持。
性能
将在内置基准测试中实现相关基准。
许可证
请参阅顶级README。
lib.rs
:
支持任意精度、任意基数和任意舍入模式的巨型浮点数库。
该库使用纯Rust实现高效的大浮点数算术。
主要类型是[FBig],表示任意精度的浮点数,[DBig]类型是支持十进制浮点数的别名。
要从字面量构建大浮点数,请使用dashu-macro
crate以提高您的便利性。
示例
use core::str::FromStr;
use core::convert::TryFrom;
use dashu_float::DBig;
// due to the limit of rust generics, the default float type
// need to be instantiate explicitly
type FBig = dashu_float::FBig;
let a = FBig::try_from(-12.34_f32).unwrap();
let b = DBig::from_str("6.022e23")?;
let c = DBig::from_parts(271828.into(), -5);
let d: DBig = "-0.0123456789".parse()?;
let e = 2 * b.ln() + DBig::ONE;
let f = &c * d.powi(10.into()) / 7;
assert_eq!(a.precision(), 24); // IEEE 754 single has 24 significant bits
assert_eq!(b.precision(), 4); // 4 decimal digits
assert!(b > c); // comparison is limited in the same base
assert!(a.to_decimal().value() < d);
assert_eq!(c.to_string(), "2.71828");
// use associated functions of the context to get full result
use dashu_base::Approximation::*;
use dashu_float::{Context, round::{mode::HalfAway, Rounding::*}};
let ctxt = Context::<HalfAway>::new(6);
assert_eq!(ctxt.exp(DBig::ONE.repr()), Inexact(c, NoOp));
可选依赖
std
(默认):为依赖项启用std
。
依赖项
~0.3–1.7MB
~36K SLoC