mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-19 03:38:13 +01:00
Added constants to rounding::CONSTANTS
This commit is contained in:
parent
89df281366
commit
4903707ce0
@ -14,41 +14,10 @@ mod rounding;
|
||||
|
||||
use crate::ast::Expr;
|
||||
use crate::radix;
|
||||
use lazy_static::lazy_static;
|
||||
use std::collections::HashMap;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
const ACCEPTABLE_COMPARISON_MARGIN: f64 = 0.00000001;
|
||||
|
||||
lazy_static! {
|
||||
static ref CONSTANTS: HashMap<&'static str, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert("3.141592", "π");
|
||||
m.insert("2.718281", "e");
|
||||
m.insert("6.283185", "τ");
|
||||
m.insert("1.618033", "ϕ");
|
||||
m.insert("1.414213", "√2");
|
||||
// Radian values for common angles
|
||||
m.insert("0.523598", "π/6");
|
||||
m.insert("0.785398", "π/4");
|
||||
m.insert("1.047197", "π/3");
|
||||
m.insert("1.570796", "π/2");
|
||||
m.insert("2.094395", "2π/3");
|
||||
m.insert("2.356194", "3π/4");
|
||||
m.insert("2.617993", "5π/6");
|
||||
m.insert("3.665191", "7π/6");
|
||||
m.insert("3.926990", "5π/4");
|
||||
m.insert("4.188790", "4π/3");
|
||||
m.insert("4.712388", "3π/2");
|
||||
m.insert("5.23598", "5π/3");
|
||||
m.insert("5.497787", "7π/4");
|
||||
m.insert("5.759586", "11π/6");
|
||||
m.insert("6.283185", "2π");
|
||||
m.insert("0.866025", "√3/2");
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
#[cfg(not(feature = "rug"))]
|
||||
macro_rules! float {
|
||||
|
@ -1,6 +1,47 @@
|
||||
use crate::float;
|
||||
use std::{collections::HashMap};
|
||||
|
||||
use crate::{float, primitive};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::{ComplexNumberType, KalkValue};
|
||||
|
||||
lazy_static! {
|
||||
static ref CONSTANTS: HashMap<&'static str, &'static str> = {
|
||||
let mut m = HashMap::new();
|
||||
m.insert("3.141592", "π");
|
||||
m.insert("9.869604", "π²");
|
||||
m.insert("0.318309", "1/π");
|
||||
m.insert("0.636619", "2/π");
|
||||
m.insert("2.718281", "e");
|
||||
m.insert("7.389056", "e²");
|
||||
m.insert("6.283185", "τ");
|
||||
m.insert("1.618033", "ϕ");
|
||||
m.insert("1.414213", "√2");
|
||||
m.insert("0.707106", "1/√2");
|
||||
m.insert("0.693147", "ln(2)");
|
||||
m.insert("2.302585", "ln(10)");
|
||||
// Radian values for common angles
|
||||
m.insert("0.392699", "π/8");
|
||||
m.insert("0.523598", "π/6");
|
||||
m.insert("0.785398", "π/4");
|
||||
m.insert("1.047197", "π/3");
|
||||
m.insert("1.570796", "π/2");
|
||||
m.insert("2.094395", "2π/3");
|
||||
m.insert("2.356194", "3π/4");
|
||||
m.insert("2.617993", "5π/6");
|
||||
m.insert("3.665191", "7π/6");
|
||||
m.insert("3.926990", "5π/4");
|
||||
m.insert("4.188790", "4π/3");
|
||||
m.insert("4.712388", "3π/2");
|
||||
m.insert("5.23598", "5π/3");
|
||||
m.insert("5.497787", "7π/4");
|
||||
m.insert("5.759586", "11π/6");
|
||||
m.insert("6.283185", "2π");
|
||||
m.insert("0.866025", "√3/2");
|
||||
m
|
||||
};
|
||||
}
|
||||
|
||||
use super::{ComplexNumberType, KalkValue, CONSTANTS};
|
||||
|
||||
pub(super) fn estimate(
|
||||
input: &KalkValue,
|
||||
@ -80,7 +121,7 @@ pub(super) fn estimate(
|
||||
.values()
|
||||
.0;
|
||||
if squared.clone().sqrt().fract() != 0f64 && squared.clone().fract() == 0f64 {
|
||||
return Some(format!("√{}", squared));
|
||||
return Some(format!("√{}", primitive!(squared) as i32));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user