Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 64 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ num = "0.4.1"
once_cell = "1.20.2"
ordered-float = "4.2.0"
owo-colors = "4.1.0"
rand = "0.8.5"
rand_chacha = "0.3.1"
rand = "0.9.0"
rand_chacha = "0.9.0"
regex = "1.10.4"
rustyline = { version = "15.0.0", optional = true, features = ["derive"] }
ryu = "1.0.17"
Expand Down
2 changes: 1 addition & 1 deletion andy-cpp-macros/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn wrap_single(
},
ty @ syn::Type::Path(_) if path_ends_with(ty, "Result") => quote! {
let value = result.map_err(|err| crate::interpreter::function::FunctionCarrier::IntoEvaluationError(Box::new(err)))?;
return Ok(Value::from(value));
return Ok(crate::interpreter::value::Value::from(value));
},
_ => quote! {
let result = crate::interpreter::value::Value::from(result);
Expand Down
14 changes: 14 additions & 0 deletions benches/programs/pi_approx.ndc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn monte_carlo_pi(num_samples) {
let inside_circle = 0;

for _ in 0..num_samples {
let x, y = randf(-1, 1), randf(-1, 1);
if x ^ 2 + y ^ 2 <= 1 {
inside_circle += 1
}
}

return (inside_circle / num_samples) * 4;
}

print(monte_carlo_pi(2_500_000).float)
1 change: 1 addition & 0 deletions src/interpreter/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Environment {
crate::stdlib::list::register(&mut env);
crate::stdlib::math::f64::register(&mut env);
crate::stdlib::math::register(&mut env);
crate::stdlib::rand::register(&mut env);
crate::stdlib::regex::register(&mut env);
crate::stdlib::sequence::extra::register(&mut env);
crate::stdlib::sequence::register(&mut env);
Expand Down
28 changes: 28 additions & 0 deletions src/interpreter/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ macro_rules! impl_binary_operator {
Int::BigInt(self.to_bigint().$method(rhs.to_bigint()))
}
}
impl std::ops::$trait<Int> for &Int {
type Output = Int;

fn $method(self, rhs: Int) -> Self::Output {
match (&self, &rhs) {
(Int::Int64(p1), Int::Int64(p2)) => {
if let Some(s) = p1.$safe_method(*p2) {
Int::Int64(s);
}
}
_ => {}
}

Int::BigInt(self.to_bigint().$method(rhs.to_bigint()))
}
}
impl std::ops::$trait<&Int> for &Int {
type Output = Int;

Expand Down Expand Up @@ -411,8 +427,20 @@ impl From<Int> for BigRational {
}
}

impl From<&Int> for BigRational {
fn from(value: &Int) -> Self {
Self::from(value.to_bigint())
}
}

impl From<Int> for Complex64 {
fn from(value: Int) -> Self {
Complex64::from(&value)
}
}

impl From<&Int> for Complex64 {
fn from(value: &Int) -> Self {
match value {
Int::Int64(i) => Self::from(i.to_f64().unwrap_or(f64::INFINITY)),
Int::BigInt(i) => Self::from(i.to_f64().unwrap_or(f64::INFINITY)),
Expand Down
Loading