Skip to content

Commit

Permalink
Publish v0.1.0 to crates.io
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Jul 17, 2024
1 parent 7bf9b5c commit d7238b7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[package]
name = "ratio"
name = "int_ratio"
version = "0.1.0"
edition = "2021"
authors = ["Yuekai Jia <[email protected]>"]
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]
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
```
23 changes: 4 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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));
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d7238b7

Please sign in to comment.