peroxide-num 0.1.4

Numerical traits for Peroxide
Documentation
  • Coverage
  • 2.78%
    1 out of 36 items documented0 out of 33 items with examples
  • Size
  • Source code size: 9.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.77 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Axect/Peroxide
    669 36 12
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Axect

Peroxide-num

Peroxide-num is a Rust crate dedicated to providing comprehensive numeric structures and operations, extending generic programming capabilities with a focus on mathematical computations.

Overview

This crate defines a set of traits for numeric operations, including basic arithmetic, power functions, trigonometric functions, exponential, and logarithmic functions. It is designed to be used with numeric types that implement these traits, allowing for a wide range of mathematical operations.

Traits

  • PowOps: Operations related to powers and roots.
  • TrigOps: Trigonometric functions.
  • ExpLogOps: Exponential and logarithmic functions.
  • Float: Define own floating point type (f32 and f64 are implemented as default).
  • Numeric: A comprehensive trait that encompasses all of the above along with standard arithmetic operations.

Example 1: Defining a Simple Numeric Type

Below is an example of how you can define your own simple numeric type that implements the Numeric trait.

#[derive(Debug, Clone, Copy, PartialOrd)]
struct SimpleNumber(f64);

impl PowOps for SimpleNumber {
    type Float = Self;

    fn powi(&self, n: i32) -> Self {
        SimpleNumber(self.0.powi(n))
    }

    fn powf(&self, f: Self::Float) -> Self {
        SimpleNumber(self.0.powf(f.0))
    }

    fn pow(&self, f: Self) -> Self {
        SimpleNumber(self.0.powf(f.0))
    }

    fn sqrt(&self) -> Self {
        SimpleNumber(self.0.sqrt())
    }
}

// Implement other required operations for SimpleNumber...
// - Add, Sub, Mul, Div, Neg
// - PowOps (implemented above)
// - TrigOps
// - ExpLogOps

impl Numeric<f64> for SimpleNumber {}

This SimpleNumber struct wraps a f64 and implements the Numeric trait, making it capable of all the operations defined in the Peroxide-num crate.

Example 2: Vec3D (3D Vector)

examples/vec3d.rs

Usage

To use this type in your own computations:

let num = SimpleNumber(2.0);
let result = num.sin(); // Compute the sine of 2.0
println!("{:?}", result); // Should display the sine of 2.0

The Peroxide-num crate is designed to be flexible and extensible, allowing for easy integration with the larger Peroxide ecosystem for scientific computing in Rust.

For more information and advanced usage, please refer to the documentation and examples provided with the crate.