# Generic programming

**nalgebra** allows several kind of generic programming, either through traits
of the **simba** crate, or by keeping the various type parameters of the
`Matrix<N, R, C, S>`

structure and the likes. In the end, this allows for:

**Genericity wrt. scalars**: the most common kind of abstraction. This allows you to write code that will work on any scalar group like`i32`

and fields like`f32`

or`f64`

.**Dimensional genericity**: allows you to write code that will work generically for 2D, 3D, and higher dimensions.

## #

Genericity wrt. scalarsThis allows to write code that works with algebraic entities constructed on top
of a generic scalar type, e.g., floating-point numbers like `f32`

or `f64`

and
in some more restrictive cases integers like `i32`

or `u64`

. This can be
achieved by keeping generic the first type parameter `N`

of any structure of
**nalgebra** (including aliases). The mandatory trait bound of `N`

is
`na::Scalar`

which imposes some simple non-mathematical properties, i.e., `N`

must copyable, printable (using the `{:?}`

format
string), and
comparable using the equality operator. Other commonly used trait bounds for
`N`

are `na::RealField`

or `na::ComplexField`

from the
simba crate. This
enables operator overloading and useful mathematical functions for signed
integers and floating point numbers respectively. Note that the `Scalar`

trait
bound does not have to be specified if `Real`

already is.