use crate::structure::ad::AD;
use peroxide_num::{ExpLogOps, PowOps, TrigOps};
use std::ops::{Add, Div, Mul, Neg, Sub};
pub trait Real:
PowOps
+ TrigOps
+ ExpLogOps
+ Neg
+ PartialOrd
+ Add<Output = Self>
+ Mul<Output = Self>
+ Div<Output = Self>
+ Sub<Output = Self>
+ Add<f64, Output = Self>
+ Mul<f64, Output = Self>
+ Div<f64, Output = Self>
+ Sub<f64, Output = Self>
+ Clone
+ Copy
{
fn to_f64(&self) -> f64;
fn from_f64(f: f64) -> Self;
fn to_ad(&self) -> AD;
}
impl Real for f64 {
fn to_f64(&self) -> f64 {
*self
}
fn from_f64(f: f64) -> Self {
f
}
fn to_ad(&self) -> AD {
AD::from(*self)
}
}
impl Real for AD {
fn to_f64(&self) -> f64 {
self.x()
}
fn from_f64(f: f64) -> Self {
AD::from(f)
}
fn to_ad(&self) -> AD {
*self
}
}