From e7d2d81f0c43c29e639fc821041d61bfa6b9f6f5 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Wed, 9 Aug 2023 09:36:08 -0400 Subject: [PATCH] fix some remainder/truncation duals --- src/forward_autodiff.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/forward_autodiff.rs b/src/forward_autodiff.rs index de7377e..5b2ca3c 100644 --- a/src/forward_autodiff.rs +++ b/src/forward_autodiff.rs @@ -463,14 +463,14 @@ where } } -impl, D: Rem> Rem for F { +impl, D: Rem> Rem for F { type Output = F; #[inline] fn rem(self, rhs: f64) -> Self::Output { // This is an approximation. There are places where the derivative doesn't exist. F { x: self.x % rhs, // x % y = x - [x/|y|]*|y| - dx: self.dx % rhs, + dx: self.dx, } } } @@ -509,7 +509,6 @@ impl, D: RemAssign> RemAssign for F { #[inline] fn rem_assign(&mut self, rhs: f64) { self.x %= rhs; - self.dx %= rhs; } } @@ -517,7 +516,6 @@ impl, D: RemAssign> RemAssign for F { #[inline] fn rem_assign(&mut self, rhs: f32) { self.x %= rhs; - self.dx %= rhs; } } @@ -915,28 +913,28 @@ where fn floor(self) -> F { F { x: self.x.floor(), - dx: self.dx, + dx: D::zero(), } } #[inline] fn ceil(self) -> F { F { x: self.x.ceil(), - dx: self.dx, + dx: D::zero(), } } #[inline] fn round(self) -> F { F { x: self.x.round(), - dx: self.dx, + dx: D::zero(), } } #[inline] fn trunc(self) -> F { F { x: self.x.trunc(), - dx: self.dx, + dx: D::zero(), } } #[inline]