mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-09 21:59:09 -07:00
global: cointime part 1
This commit is contained in:
@@ -139,6 +139,24 @@ impl Div<usize> for Dollars {
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<StoredF64> for Dollars {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: StoredF64) -> Self::Output {
|
||||
self / f64::from(rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<f64> for Dollars {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: f64) -> Self::Output {
|
||||
if self.is_nan() || rhs == 0.0 {
|
||||
Dollars::NAN
|
||||
} else {
|
||||
Dollars::from(Cents::from(Self::from(self.0 / rhs)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<Bitcoin> for Dollars {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: Bitcoin) -> Self::Output {
|
||||
@@ -178,6 +196,13 @@ impl Mul<usize> for Close<Dollars> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<StoredF64> for Close<Dollars> {
|
||||
type Output = Dollars;
|
||||
fn mul(self, rhs: StoredF64) -> Self::Output {
|
||||
*self * rhs
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<f64> for Dollars {
|
||||
type Output = Dollars;
|
||||
fn mul(self, rhs: f64) -> Self::Output {
|
||||
|
||||
@@ -524,3 +524,13 @@ where
|
||||
Self(self.0 / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T> Mul<usize> for Close<T>
|
||||
// where
|
||||
// T: Mul<usize, Output = T>,
|
||||
// {
|
||||
// type Output = Self;
|
||||
// fn mul(self, rhs: usize) -> Self::Output {
|
||||
// Self(self.0 * rhs)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -9,7 +9,7 @@ use byteview::ByteView;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
use crate::{CheckedSub, copy_first_8bytes};
|
||||
use crate::{CheckedSub, StoredF64, copy_first_8bytes};
|
||||
|
||||
use super::{Bitcoin, Cents, Dollars, Height};
|
||||
|
||||
@@ -112,6 +112,13 @@ impl Mul<Height> for Sats {
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<StoredF64> for Sats {
|
||||
type Output = Self;
|
||||
fn mul(self, rhs: StoredF64) -> Self::Output {
|
||||
Sats::from((self.0 as f64 * f64::from(rhs)) as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sum for Sats {
|
||||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||
let sats: u64 = iter.map(|sats| sats.0).sum();
|
||||
|
||||
@@ -51,6 +51,13 @@ impl Div<usize> for StoredF64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Div<StoredF64> for StoredF64 {
|
||||
type Output = Self;
|
||||
fn div(self, rhs: Self) -> Self::Output {
|
||||
Self(self.0 / rhs.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for StoredF64 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
|
||||
Reference in New Issue
Block a user