diff --git a/Cargo.toml b/Cargo.toml index a6d0945..e673095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,14 @@ [package] -name = "ratio" +name = "int_ratio" version = "0.1.0" edition = "2021" authors = ["Yuekai Jia "] -description = "The type of ratios and related operations" +description = "The type of ratios represented by two integers." license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0" homepage = "https://github.com/arceos-org/arceos" -repository = "https://github.com/arceos-org/ratio" -documentation = "https://arceos-org.github.io/ratio" +repository = "https://github.com/arceos-org/int_ratio" +documentation = "https://docs.rs/int_ratio" +keywords = ["ratio", "fraction", "integer", "approximation"] +categories = ["mathematics"] [dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..29c036f --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# int_ratio + +[![Crates.io](https://img.shields.io/crates/v/int_ratio)](https://crates.io/crates/int_ratio) +[![Docs.rs](https://docs.rs/int_ratio/badge.svg)](https://docs.rs/int_ratio) +[![CI](https://github.com/arceos-org/int_ratio/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/arceos-org/int_ratio/actions/workflows/ci.yml) + +The type of ratios and related operations. + +A **ratio** is the result of dividing two **integers**, i.e., the numerator and +denominator. + +## Examples + +```rust +use int_ratio::Ratio; + +let ratio = Ratio::new(1, 3); // 1 / 3 +assert_eq!(ratio.mul_trunc(20), 6); // trunc(20 * 1 / 3) = trunc(6.66..) = 6 +assert_eq!(ratio.mul_round(20), 7); // round(20 * 1 / 3) = round(6.66..) = 7 +println!("{:?}", ratio); // Ratio(1/3 ~= 1431655765/4294967296) +``` diff --git a/src/lib.rs b/src/lib.rs index 5ae5383..5cacebb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,5 @@ -//! The type of ratios and related operations. -//! -//! A **ratio** is the result of dividing two integers, i.e., the numerator and -//! denominator. -//! -//! # Examples -//! -//! ``` -//! use ratio::Ratio; -//! -//! let ratio = Ratio::new(1, 3); // 1 / 3 -//! assert_eq!(ratio.mul_trunc(20), 6); // trunc(20 * 1 / 3) = trunc(6.66..) = 6 -//! assert_eq!(ratio.mul_round(20), 7); // round(20 * 1 / 3) = round(6.66..) = 7 -//! println!("{:?}", ratio); // Ratio(1/3 ~= 1431655765/4294967296) -//! ``` - #![cfg_attr(not(test), no_std)] +#![doc = include_str!("../README.md")] use core::{cmp::PartialEq, fmt}; @@ -84,7 +69,7 @@ impl Ratio { /// # Examples /// /// ``` - /// use ratio::Ratio; + /// use int_ratio::Ratio; /// /// let ratio = Ratio::new(1, 2); /// assert_eq!(ratio.inverse(), Ratio::new(2, 1)); @@ -98,7 +83,7 @@ impl Ratio { /// # Examples /// /// ``` - /// use ratio::Ratio; + /// use int_ratio::Ratio; /// /// let ratio = Ratio::new(2, 3); /// assert_eq!(ratio.mul_trunc(99), 66); // 99 * 2 / 3 = 66 @@ -114,7 +99,7 @@ impl Ratio { /// # Examples /// /// ``` - /// use ratio::Ratio; + /// use int_ratio::Ratio; /// /// let ratio = Ratio::new(2, 3); /// assert_eq!(ratio.mul_round(99), 66); // 99 * 2 / 3 = 66