### 5 releases

0.1.4 | Nov 25, 2023 |
---|---|

0.1.3 | Nov 9, 2023 |

0.1.2 | Nov 9, 2023 |

0.1.1 | Nov 9, 2023 |

0.1.0 | Nov 9, 2023 |

#**641** in Math

**343** downloads per month

Used in **6** crates
(2 directly)

**MIT/Apache**

10KB

183 lines

# Peroxide-num

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

## 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

: Operations related to powers and roots.`PowOps`

: Trigonometric functions.`TrigOps`

: Exponential and logarithmic functions.`ExpLogOps`

: Define own floating point type (`Float`

and`f32`

are implemented as default).`f64`

: A comprehensive trait that encompasses all of the above along with standard arithmetic operations.`Numeric`

## Example 1: Defining a Simple Numeric Type

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

trait.`Numeric`

`#``[``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

struct wraps a `SimpleNumber`

and implements the `f64`

trait, making it capable of all the operations defined in the `Numeric`

crate.`Peroxide -num`

## Example 2: `Vec3D`

(3D Vector)

`Vec3D`

## 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

crate is designed to be flexible and extensible, allowing for easy integration with the larger `Peroxide -num`

`Peroxide`

ecosystem for scientific computing in Rust.For more information and advanced usage, please refer to the documentation and examples provided with the crate.