Use f64 instead.

This commit is contained in:
2018-10-23 14:59:58 +02:00
parent 1b840e737d
commit b4cce71df4
5 changed files with 38 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
use std::ops;
fn det(m: &[f32], x: usize) -> f32 {
fn det(m: &[f64], x: usize) -> f64 {
if x == 1 {
m[0]
} else if x == 2 {
@@ -17,7 +17,7 @@ fn det(m: &[f32], x: usize) -> f32 {
.map(|(_, v)| *v)
.collect::<Vec<_>>();
d += (-1.0f32).powi(n as i32) * m[n] * det(&ms, x - 1);
d += (-1.0f64).powi(n as i32) * m[n] * det(&ms, x - 1);
}
d
@@ -26,7 +26,7 @@ fn det(m: &[f32], x: usize) -> f32 {
#[derive(Clone, Debug)]
pub struct Matrix {
data: Box<[f32]>,
data: Box<[f64]>,
height: usize,
width: usize,
}
@@ -80,7 +80,7 @@ impl Matrix {
matrix
}
pub fn determinant(&self) -> f32 {
pub fn determinant(&self) -> f64 {
debug_assert!(self.width == self.height);
det(&self.data, self.width)
@@ -122,7 +122,7 @@ impl Matrix {
}
impl ops::Index<(usize, usize)> for Matrix {
type Output = f32;
type Output = f64;
fn index(&self, pos: (usize, usize)) -> &Self::Output {
&self.data[(self.width * pos.0) + pos.1]
@@ -135,7 +135,7 @@ impl ops::IndexMut<(usize, usize)> for Matrix {
}
}
impl<'a> ops::Mul<&'a Matrix> for f32 {
impl<'a> ops::Mul<&'a Matrix> for f64 {
type Output = Matrix;
fn mul(self, rhs: &'a Matrix) -> Matrix {