### 24 releases (4 breaking)

0.5.5 | Apr 22, 2022 |
---|---|

0.5.4 | Apr 4, 2022 |

0.4.5 | Mar 31, 2022 |

0.3.0 | Mar 27, 2022 |

0.1.6 | Jan 30, 2022 |

#**561** in Math

**104** downloads per month

Used in **2** crates

**Custom license**

110KB

2.5K
SLoC

# Mixed Num

No-STD abstraction layer enabling numerical functions to be implemented once, and simultaneously support both real and complex numbers with, int, fixed and floating point types.

The library supplies complex structs

and `Polar <T>`

`Cartesian``<`T`>`

with no-std implementation of math traits, including `MixedNum`

traits.Some interoperability with num::Complex is implemented.

This is an experimental library.

This library support fixed point numbers using the fixed crate. It uses num for floating point generics.

The package.

The documentation.

Release notes are found under RELEASES.md.

###
`lib.rs`

:

No-STD abstraction layer enabling numerical functions to be implemented once, and simultaneously support both real and complex numbers with, int, fixed and floating point types.

This is an experimental library.

## Example

`use` `mixed_num``::``*``;`
`use` `mixed_num``::``traits``::``*``;`
`use` `fixed``::``{``types``::``extra``::``U27``,` FixedI32`}``;`
`let` number `=` `FixedI32``::``<`U27`>``::`from_num`(``0.``6``f32``)``;`
`let` res`:``f32` `=` number`.``mixed_atan``(``)``.``mixed_to_num``(``)``;`
`assert_eq!``{` res`,` `0.``5404195` `}``;`
`let` number `=` `0.``6``f32``;`
`let` res`:``f32` `=` number`.``mixed_atan``(``)``.``mixed_to_num``(``)``;`
`assert_eq!``{` res`,` `0.``5404195` `}``;`

The library supplies complex structs

and `Polar <T>`

`Cartesian``<`T`>`

with no-std implementation of math traits, including `MixedNum`

traits.Some interoperability with num::Complex is implemented.

## Example

`use` `mixed_num``::``*``;`
`use` `mixed_num``::``traits``::``*``;`
`let` number `=` `Cartesian``::`new`(``1``f32``,``2``f32``)``;`
`assert_eq!``{` number`.``to_string``(``)``,` `"`1+2i`"` `}``;`
`let` polar_number `=` number`.``to_polar``(``)``;`
`assert_eq!``{` polar_number`.``to_string``(``)``,` `"`2.236068∠1.1071488`"` `}``;`
`let` polar_conj`:` `Polar``<``f32``>` `=` polar_number`.``conj``(``)``;`
`assert_eq!``{` polar_conj`.``to_string``(``)``,` `"`2.236068∠-1.1071488`"` `}``;`

Selected

traits are implemented on the complex structs.`core ::`ops

## Example

`use` `mixed_num``::``*``;`
`use` `mixed_num``::``traits``::``*``;`
`let` `mut` `c_num` `=` `Cartesian``::`new`(``1``f32``,``2``f32``)``;`
`c_num` `=` `c_num``*``c_num``;`
`assert_eq!``{` `c_num``.``to_string``(``)``,` `"`-3+4i`"` `}``;`

This includes support for operation of mixed types.

## Example

`use` `mixed_num``::``*``;`
`use` `mixed_num``::``traits``::``*``;`
`let` `mut` `c_num` `=` `Cartesian``::`new`(``1``f32``,``2``f32``)``;`
`c_num` `=` `c_num``*``2``f64``;`
`assert_eq!``{` `c_num``.``to_string``(``)``,` `"`2+4i`"` `}``;`

#### Dependencies

~3MB

~61K SLoC