mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
README.md
lalgebra_scalar
Instructions
Define a Scalar
trait which must implement the operations Addition, Subtraction, Multiplication and Division (you might also have to use more restrictions). For this use a trait inheritance (supertraits)
Another condition for a number to be a scalar is to have a zero (neutral element in the addition) and a one (neutral element in the multiplication). Therefore the Scalar
trait will require 2 functions zero() and one() (as shown)
After finishing completing the declaration of the trait, implement the Scalar
trait for u32, u64, i32, i64, f32 and f64.
Notions
Expected Function (The signature must be completed)
You need add the impl for each cases asked in the subject
pub trait Scalar: _ {
type Item;
fn zero() -> Self::Item;
fn one() -> Self::Item;
}
Usage
Here is a program to test your function.
use lalgebra_scalar::*;
fn main() {
println!("{:?}", f64::zero());
println!("{:?}", i32::zero());
println!("{:?}", f64::one());
println!("{:?}", i32::one());
}
And its output:
student@ubuntu:~/[[ROOT]]/test$ cargo run
0.0
0
1.0
1
student@ubuntu:~/[[ROOT]]/test$