add golden ratio and its conjugate to constants
This commit is contained in:
parent
1167020994
commit
b22a08b66f
|
@ -74,6 +74,14 @@ The conversions supported cover the following cases.
|
|||
|
||||
## What’s new
|
||||
|
||||
### Version 0.5.7 news (unreleased)
|
||||
|
||||
* The [`PHI`][phi-0-5-7] and [`FRAC_1_PHI`][f1phi--0-5-7] constants
|
||||
were added.
|
||||
|
||||
[f1phi-0-5-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/consts/constant.FRAC_1_PHI.html
|
||||
[phi-0-5-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/consts/constant.PHI.html
|
||||
|
||||
### Version 0.5.6 news (2020-05-01)
|
||||
|
||||
**This release is meant to be the last release before version 1.0.0:**
|
||||
|
|
|
@ -5,6 +5,11 @@ modification, are permitted in any medium without royalty provided the
|
|||
copyright notice and this notice are preserved. This file is offered
|
||||
as-is, without any warranty. -->
|
||||
|
||||
Version 0.5.7 (unreleased)
|
||||
==========================
|
||||
|
||||
* The `PHI` and `FRAC_1_PHI` constants were added.
|
||||
|
||||
Version 0.5.6 (2020-05-01)
|
||||
==========================
|
||||
|
||||
|
|
|
@ -109,6 +109,8 @@ fn main() {
|
|||
print("log<sub>10</sub> e", "LOG10_E", float(1).exp().log10());
|
||||
print("ln 2", "LN_2", float(2).ln());
|
||||
print("ln 10", "LN_10", float(10).ln());
|
||||
print("φ", "PHI", float(1.25).sqrt() + 0.5);
|
||||
print("Φ = 1/φ", "FRAC_1_PHI", float(1.25).sqrt() - 0.5);
|
||||
}
|
||||
```
|
||||
*/
|
||||
|
@ -225,6 +227,14 @@ pub const LN_2: U0F128 = U0F128::from_bits(0xB172_17F7_D1CF_79AB_C9E3_B398_03F2_
|
|||
// LN_10 = 2.302585092994045684017991454684364207601...
|
||||
pub const LN_10: U2F126 = U2F126::from_bits(0x935D_8DDD_AAA8_AC16_EA56_D62B_82D3_0A28);
|
||||
|
||||
/// φ = 1.61803…
|
||||
// PHI = 1.618033988749894848204586834365638117720...
|
||||
pub const PHI: U1F127 = U1F127::from_bits(0xCF1B_BCDC_BFA5_3E0A_F9CE_6030_2E76_E41A);
|
||||
|
||||
/// Φ = 1/φ = 0.618033…
|
||||
// FRAC_1_PHI = 0.6180339887498948482045868343656381177203...
|
||||
pub const FRAC_1_PHI: U0F128 = U0F128::from_bits(0x9E37_79B9_7F4A_7C15_F39C_C060_5CED_C834);
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::cognitive_complexity, clippy::float_cmp)]
|
||||
mod tests {
|
||||
|
@ -274,6 +284,11 @@ mod tests {
|
|||
assert_eq!(f16::from_fixed(LOG10_E), f16::LOG10_E);
|
||||
assert_eq!(f16::from_fixed(LN_2), f16::LN_2);
|
||||
assert_eq!(f16::from_fixed(LN_10), f16::LN_10);
|
||||
assert_eq!(f16::from_fixed(PHI), f16::from_f32(1.25f32.sqrt() + 0.5));
|
||||
assert_eq!(
|
||||
f16::from_fixed(FRAC_1_PHI),
|
||||
f16::from_f32(1.25f32.sqrt() - 0.5)
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "f16")]
|
||||
|
@ -316,6 +331,11 @@ mod tests {
|
|||
assert_eq!(bf16::from_fixed(LOG10_E), bf16::LOG10_E);
|
||||
assert_eq!(bf16::from_fixed(LN_2), bf16::LN_2);
|
||||
assert_eq!(bf16::from_fixed(LN_10), bf16::LN_10);
|
||||
assert_eq!(bf16::from_fixed(PHI), f16::from_f32(1.25f32.sqrt() + 0.5));
|
||||
assert_eq!(
|
||||
bf16::from_fixed(FRAC_1_PHI),
|
||||
f16::from_f32(1.25f32.sqrt() - 0.5)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -350,6 +370,8 @@ mod tests {
|
|||
assert_eq!(f32::from_fixed(LOG10_E), f32::consts::LOG10_E);
|
||||
assert_eq!(f32::from_fixed(LN_2), f32::consts::LN_2);
|
||||
assert_eq!(f32::from_fixed(LN_10), f32::consts::LN_10);
|
||||
assert_eq!(f32::from_fixed(PHI), 1.25f32.sqrt() + 0.5);
|
||||
assert_eq!(f32::from_fixed(FRAC_1_PHI), (1.25f64.sqrt() - 0.5) as f32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -384,6 +406,9 @@ mod tests {
|
|||
assert_eq!(f64::from_fixed(LOG10_E), f64::consts::LOG10_E);
|
||||
assert_eq!(f64::from_fixed(LN_2), f64::consts::LN_2);
|
||||
assert_eq!(f64::from_fixed(LN_10), f64::consts::LN_10);
|
||||
assert_eq!(f64::from_fixed(PHI), 1.25f64.sqrt() + 0.5);
|
||||
// Since 0.5 < FRAC_1_PHI < 1.0, we use EPSILON / 2.
|
||||
assert!((f64::from_fixed(FRAC_1_PHI) - (1.25f64.sqrt() - 0.5)).abs() <= f64::EPSILON / 2.0);
|
||||
}
|
||||
|
||||
fn compare_parse<F: Fixed>(f: F, s: &str)
|
||||
|
@ -425,5 +450,7 @@ mod tests {
|
|||
compare_parse(LOG10_E, "0.4342944819032518276511289189166050822943");
|
||||
compare_parse(LN_2, "0.6931471805599453094172321214581765680755");
|
||||
compare_parse(LN_10, "2.302585092994045684017991454684364207601");
|
||||
compare_parse(PHI, "1.618033988749894848204586834365638117720");
|
||||
compare_parse(FRAC_1_PHI, "0.6180339887498948482045868343656381177203");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,6 +132,9 @@ let _ = Fix::LN_2;
|
|||
|
||||
/// ln 2 = 0.693147…
|
||||
pub const LN_2: $Fixed<Frac> = shift!(LN_2, $Fixed<Frac>);
|
||||
|
||||
/// Φ = 1/φ = 0.618033…
|
||||
pub const FRAC_1_PHI: $Fixed<Frac> = shift!(FRAC_1_PHI, $Fixed<Frac>);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,6 +201,9 @@ let _ = Fix::LOG2_E;
|
|||
|
||||
/// log<sub>2</sub> e = 1.44269…
|
||||
pub const LOG2_E: $Fixed<Frac> = shift!(LOG2_E, 127, $Fixed<Frac>);
|
||||
|
||||
/// φ = 1.61803…
|
||||
pub const PHI: $Fixed<Frac> = shift!(PHI, 127, $Fixed<Frac>);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue