Skip to content

Commit

Permalink
v0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
neogenie committed Jan 1, 2025
1 parent 3f7dc6d commit 59b6959
Show file tree
Hide file tree
Showing 19 changed files with 362 additions and 191 deletions.
19 changes: 19 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ All user-visible changes to this library will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/), as described
for Rust libraries in [RFC #1105](https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md)

## [0.1.9] – 2025-01-01

### Breaking changes

* Replace `decimal::Category` with `core::num::FpCategory`.

### Changed

* Micro-optimizations in rounding.
* Make `.from_parts()` constructor public (Way to directly create decimals with scale without dividing? #3).

### Added

* Implement `TryFrom<Decimal>` for `UnsignedDecimal` and `From<UnsignedDecimal>` for `Decimal` traits.

### Fixed

* Fixed minor issues with ceil/floor rounding.

## [0.1.8] – 2024-12-28

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastnum"
version = "0.1.8"
version = "0.1.9"
edition = "2021"
authors = ["Neo"]
description = "Fast decimal numbers library"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fastnum = { version = "0.1", features = ["serde"] } # enables the "serde" featur
## Example Usage

```rust
use fastnum::{udec256, UD256};
use fastnum::*;

fn main() {
const ZERO: UD256 = udec256!(0);
Expand Down Expand Up @@ -180,7 +180,7 @@ The `utoipa` feature enables support of `fastnum` decimals for autogenerated Ope
| Performance | 🚀🚀🚀🚀🚀 | 🚀🚀🚀🚀 | 🚀 | 🚀🚀🚀🚀 | 🚀🚀🚀🚀 |
| `no-std` |||| | |

- <sup>*</sup> Precision is arbitrary but fixed.
<sup>*</sup> Precision is arbitrary but fixed.

[Benchmarks]: #competition--benchmarks

Expand Down
2 changes: 0 additions & 2 deletions src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub(crate) mod doc;
pub(crate) mod round;
pub(crate) mod udec;

mod category;
mod context;
mod sign;
mod flags;
Expand All @@ -29,7 +28,6 @@ pub(crate) mod errors;
#[macro_use]
mod macros;

pub use category::Category;
pub use context::{Context, RoundingMode, SignalsTraps};
pub use dec::Decimal;
pub use errors::{ParseError, DecimalError};
Expand Down
34 changes: 0 additions & 34 deletions src/decimal/category.rs

This file was deleted.

31 changes: 15 additions & 16 deletions src/decimal/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod scale;

pub(crate) use control_block::ControlBlock;

use core::{cmp::Ordering, fmt, panic};
use core::{cmp::Ordering, fmt, num::FpCategory, panic};

use crate::{
decimal::{
Expand All @@ -23,8 +23,7 @@ use crate::{
intrinsics::{clength, Intrinsics},
math::consts::Consts,
},
doc, Category, Context, DecimalError, Flags, ParseError, RoundingMode, Sign, Signal,
UnsignedDecimal,
doc, Context, DecimalError, Flags, ParseError, RoundingMode, Sign, Signal, UnsignedDecimal,
},
int::UInt,
};
Expand Down Expand Up @@ -63,7 +62,6 @@ impl<const N: usize> Decimal<N> {
///
/// assert_eq!(D256::from_parts(u256!(12345), -4, Sign::Minus, Context::default()),dec256!(-1.2345));
/// ```
#[cfg(feature = "dev")]
#[track_caller]
#[must_use]
#[inline]
Expand Down Expand Up @@ -296,27 +294,28 @@ impl<const N: usize> Decimal<N> {
/// # Examples
///
/// ```
/// use fastnum::{dec256, D256, decimal::Category};
/// use core::num::FpCategory;
/// use fastnum::{dec256, D256};
///
/// let num = dec256!(12.4);
/// let inf = D256::INFINITY;
///
/// assert_eq!(num.classify(), Category::Normal);
/// assert_eq!(inf.classify(), Category::Infinite);
/// assert_eq!(num.classify(), FpCategory::Normal);
/// assert_eq!(inf.classify(), FpCategory::Infinite);
/// ```
#[must_use]
#[inline]
pub const fn classify(&self) -> Category {
pub const fn classify(&self) -> FpCategory {
if self.cb.is_nan() {
Category::Nan
FpCategory::Nan
} else if self.cb.is_infinity() {
Category::Infinite
FpCategory::Infinite
} else if self.digits.is_zero() {
Category::Zero
FpCategory::Zero
} else if self.is_subnormal() {
Category::Subnormal
FpCategory::Subnormal
} else {
Category::Normal
FpCategory::Normal
}
}

Expand All @@ -326,7 +325,7 @@ impl<const N: usize> Decimal<N> {
/// # Examples
///
/// ```
/// use fastnum::{dec256, D256, decimal::Category};
/// use fastnum::*;
///
/// let num = dec256!(12.4);
/// let subnormal = dec256!(1E-30000) / dec256!(1E2768);
Expand All @@ -349,15 +348,15 @@ impl<const N: usize> Decimal<N> {
#[must_use]
#[inline]
pub const fn is_normal(&self) -> bool {
matches!(self.classify(), Category::Normal)
matches!(self.classify(), FpCategory::Normal)
}

/// Return `true` if the number is [subnormal] and `false` otherwise.
///
/// # Examples
///
/// ```
/// use fastnum::{dec256, D256, decimal::Category};
/// use fastnum::*;
///
/// let num = dec256!(12.4);
/// let subnormal = dec256!(1E-30000) / dec256!(1E2768);
Expand Down
10 changes: 6 additions & 4 deletions src/decimal/dec/impls/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ use crate::{
int::UInt,
};

type D<const N: usize> = Decimal<N>;

macro_rules! from_uint {
($($uint: tt),*) => {
$(
impl<const N: usize> From<$uint> for Decimal<N>
impl<const N: usize> From<$uint> for D<N>
{
#[inline]
fn from(n: $uint) -> Self {
Expand All @@ -23,7 +25,7 @@ macro_rules! from_uint {
macro_rules! from_int {
($($int: tt),*) => {
$(
impl<const N: usize> From<$int> for Decimal<N> {
impl<const N: usize> From<$int> for D<N> {
#[inline]
fn from(n: $int) -> Self {
let cb =
Expand All @@ -43,7 +45,7 @@ macro_rules! from_int {
from_uint!(u8, u16, u32, u64, u128, usize);
from_int!(i8, i16, i32, i64, i128, isize);

impl<const N: usize> TryFrom<f32> for Decimal<N> {
impl<const N: usize> TryFrom<f32> for D<N> {
type Error = ParseError;

#[inline]
Expand All @@ -52,7 +54,7 @@ impl<const N: usize> TryFrom<f32> for Decimal<N> {
}
}

impl<const N: usize> TryFrom<f64> for Decimal<N> {
impl<const N: usize> TryFrom<f64> for D<N> {
type Error = ParseError;

#[inline]
Expand Down
Loading

0 comments on commit 59b6959

Please sign in to comment.