Transfer commit
This commit is contained in:
4
src/external/bool/mod.rs
vendored
4
src/external/bool/mod.rs
vendored
@@ -3,10 +3,10 @@ mod boolean;
|
||||
mod ifthenelse;
|
||||
pub use boolean::Boolean;
|
||||
|
||||
use crate::project::{Loader, fnlib_loader};
|
||||
use crate::project::{Loader, extlib_loader};
|
||||
|
||||
pub fn bool() -> impl Loader {
|
||||
fnlib_loader(vec![
|
||||
extlib_loader(vec![
|
||||
("ifthenelse", Box::new(ifthenelse::IfThenElse1)),
|
||||
("equals", Box::new(equals::Equals2))
|
||||
])
|
||||
|
||||
4
src/external/conv/mod.rs
vendored
4
src/external/conv/mod.rs
vendored
@@ -1,11 +1,11 @@
|
||||
use crate::project::{fnlib_loader, Loader};
|
||||
use crate::project::{extlib_loader, Loader};
|
||||
|
||||
mod to_string;
|
||||
mod parse_float;
|
||||
mod parse_uint;
|
||||
|
||||
pub fn conv() -> impl Loader {
|
||||
fnlib_loader(vec![
|
||||
extlib_loader(vec![
|
||||
("parse_float", Box::new(parse_float::ParseFloat1)),
|
||||
("parse_uint", Box::new(parse_uint::ParseUint1)),
|
||||
("to_string", Box::new(to_string::ToString1))
|
||||
|
||||
4
src/external/cpsio/mod.rs
vendored
4
src/external/cpsio/mod.rs
vendored
@@ -1,10 +1,10 @@
|
||||
use crate::project::{Loader, fnlib_loader};
|
||||
use crate::project::{Loader, extlib_loader};
|
||||
|
||||
mod print;
|
||||
mod readline;
|
||||
|
||||
pub fn cpsio() -> impl Loader {
|
||||
fnlib_loader(vec![
|
||||
extlib_loader(vec![
|
||||
("print", Box::new(print::Print2)),
|
||||
("readline", Box::new(readline::Readln2))
|
||||
])
|
||||
|
||||
4
src/external/num/mod.rs
vendored
4
src/external/num/mod.rs
vendored
@@ -2,10 +2,10 @@ mod numeric;
|
||||
pub mod operators;
|
||||
pub use numeric::Numeric;
|
||||
|
||||
use crate::project::{fnlib_loader, Loader};
|
||||
use crate::project::{extlib_loader, Loader};
|
||||
|
||||
pub fn num() -> impl Loader {
|
||||
fnlib_loader(vec![
|
||||
extlib_loader(vec![
|
||||
("add", Box::new(operators::add::Add2)),
|
||||
("subtract", Box::new(operators::subtract::Subtract2)),
|
||||
("multiply", Box::new(operators::multiply::Multiply2)),
|
||||
|
||||
54
src/external/num/numeric.rs
vendored
54
src/external/num/numeric.rs
vendored
@@ -14,15 +14,29 @@ pub enum Numeric {
|
||||
Num(NotNan<f64>)
|
||||
}
|
||||
|
||||
impl Numeric {
|
||||
/// Wrap a f64 in a Numeric
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// if the value is NaN or Infinity.try_into()
|
||||
fn num<T>(value: T) -> Self where T: Into<f64> {
|
||||
let f = value.into();
|
||||
assert!(f.is_finite(), "unrepresentable number");
|
||||
NotNan::try_from(f).map(Self::Num).expect("not a number")
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Numeric {
|
||||
type Output = Numeric;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
match (self, rhs) {
|
||||
(Numeric::Uint(a), Numeric::Uint(b)) => Numeric::Uint(a + b),
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::Num(a + b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) | (Numeric::Num(b), Numeric::Uint(a))
|
||||
=> Numeric::Num(NotNan::new(a as f64).unwrap() + b)
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::num(a + b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) |
|
||||
(Numeric::Num(b), Numeric::Uint(a))
|
||||
=> Numeric::num::<f64>(a as f64 + *b)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +48,10 @@ impl Sub for Numeric {
|
||||
match (self, rhs) {
|
||||
(Numeric::Uint(a), Numeric::Uint(b)) if b < a => Numeric::Uint(a - b),
|
||||
(Numeric::Uint(a), Numeric::Uint(b))
|
||||
=> Numeric::Num(NotNan::new(a as f64 - b as f64).unwrap()),
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::Num(a - b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) | (Numeric::Num(b), Numeric::Uint(a))
|
||||
=> Numeric::Num(NotNan::new(a as f64).unwrap() - b)
|
||||
=> Numeric::num(a as f64 - b as f64),
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::num(a - b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) => Numeric::num(a as f64 - *b),
|
||||
(Numeric::Num(a), Numeric::Uint(b)) => Numeric::num(*a - b as f64)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,8 +62,9 @@ impl Mul for Numeric {
|
||||
fn mul(self, rhs: Self) -> Self::Output {
|
||||
match (self, rhs) {
|
||||
(Numeric::Uint(a), Numeric::Uint(b)) => Numeric::Uint(a * b),
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::Num(a * b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) | (Numeric::Num(b), Numeric::Uint(a))
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::num(a * b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) |
|
||||
(Numeric::Num(b), Numeric::Uint(a))
|
||||
=> Numeric::Num(NotNan::new(a as f64).unwrap() * b)
|
||||
}
|
||||
}
|
||||
@@ -59,9 +74,9 @@ impl Div for Numeric {
|
||||
type Output = Numeric;
|
||||
|
||||
fn div(self, rhs: Self) -> Self::Output {
|
||||
let a = match self { Numeric::Uint(i) => i as f64, Numeric::Num(f) => *f };
|
||||
let b = match rhs { Numeric::Uint(i) => i as f64, Numeric::Num(f) => *f };
|
||||
Numeric::Num(NotNan::new(a / b).unwrap())
|
||||
let a: f64 = self.into();
|
||||
let b: f64 = rhs.into();
|
||||
Numeric::num(a / b)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,9 +86,9 @@ impl Rem for Numeric {
|
||||
fn rem(self, rhs: Self) -> Self::Output {
|
||||
match (self, rhs) {
|
||||
(Numeric::Uint(a), Numeric::Uint(b)) => Numeric::Uint(a % b),
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::Num(a % b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) | (Numeric::Num(b), Numeric::Uint(a))
|
||||
=> Numeric::Num(NotNan::new(a as f64).unwrap() % b)
|
||||
(Numeric::Num(a), Numeric::Num(b)) => Numeric::num(a % b),
|
||||
(Numeric::Uint(a), Numeric::Num(b)) => Numeric::num(a as f64 % *b),
|
||||
(Numeric::Num(a), Numeric::Uint(b)) => Numeric::num(*a % b as f64)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,4 +123,13 @@ impl From<Numeric> for String {
|
||||
Numeric::Num(n) => n.to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<f64> for Numeric {
|
||||
fn into(self) -> f64 {
|
||||
match self {
|
||||
Numeric::Num(n) => *n,
|
||||
Numeric::Uint(i) => i as f64
|
||||
}
|
||||
}
|
||||
}
|
||||
4
src/external/str/mod.rs
vendored
4
src/external/str/mod.rs
vendored
@@ -2,10 +2,10 @@ mod concatenate;
|
||||
mod cls2str;
|
||||
mod char_at;
|
||||
pub use cls2str::cls2str;
|
||||
use crate::project::{Loader, fnlib_loader};
|
||||
use crate::project::{Loader, extlib_loader};
|
||||
|
||||
pub fn str() -> impl Loader {
|
||||
fnlib_loader(vec![
|
||||
extlib_loader(vec![
|
||||
("concatenate", Box::new(concatenate::Concatenate2))
|
||||
])
|
||||
}
|
||||
Reference in New Issue
Block a user