summaryrefslogtreecommitdiff
path: root/matrix-std/src/math.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-29 17:04:28 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-29 17:04:28 -0500
commit5d2747e26f51cc2344a6bd95f93457248fdfebd8 (patch)
tree8755b4068166c3854d26817683ce438a771ab319 /matrix-std/src/math.rs
parentmore mat, sys, and os stdlib functions, better matrix printing, other fixes (diff)
downloadmatrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.gz
matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.tar.bz2
matrix-5d2747e26f51cc2344a6bd95f93457248fdfebd8.zip
fin prob
Diffstat (limited to '')
-rw-r--r--matrix-std/src/math.rs (renamed from matrix-stdlib/src/math.rs)13
1 files changed, 6 insertions, 7 deletions
diff --git a/matrix-stdlib/src/math.rs b/matrix-std/src/math.rs
index 3f33951..111544c 100644
--- a/matrix-stdlib/src/math.rs
+++ b/matrix-std/src/math.rs
@@ -1,9 +1,8 @@
use core::f64;
use std::f64::{consts::{PI, E, TAU}, NAN, INFINITY};
-
-use matrix::{vm::Vm, value::{Value, Matrix}, Result, unpack_args, Rational64, Complex64};
+use matrix_lang::prelude::*;
use matrix_macros::native_func;
-use crate::{error, VmArgs};
+use crate::{error, VmArgs, unpack_args};
#[native_func(1)]
fn trans(_: VmArgs, args: Vec<Value>) -> Result<Value> {
@@ -280,7 +279,7 @@ macro_rules! trig {
fn $type(_: VmArgs, args: Vec<Value>) -> Result<Value> {
use Value as V;
let [value] = unpack_args!(args);
- match value.promote_trig() {
+ match value.floaty() {
V::Float(f) => Ok(V::Float(f.$type())),
V::Complex(c) => Ok(V::Complex(c.$type())),
v => error!("cannot compute {} on {v}", stringify!($type))
@@ -295,7 +294,7 @@ macro_rules! trigf {
fn $str(_: VmArgs, args: Vec<Value>) -> Result<Value> {
use Value as V;
let [value] = unpack_args!(args);
- match value.promote_trig() {
+ match value.floaty() {
V::Float(f) => Ok(V::Float(f.$type())),
v => error!("cannot compute {} on {v}", stringify!($str))
}
@@ -307,7 +306,7 @@ macro_rules! trigf {
fn log(_: VmArgs, args: Vec<Value>) -> Result<Value> {
use Value as V;
let [base, value] = unpack_args!(args);
- match (base.promote_trig(), value.promote_trig()) {
+ match (base.floaty(), value.floaty()) {
(V::Float(base), V::Float(arg)) => Ok(V::Float(arg.log(base))),
(V::Float(base), V::Complex(arg)) => Ok(V::Complex(arg.log(base))),
(V::Complex(base), V::Float(arg)) => Ok(V::Complex(arg.ln() / base.ln())),
@@ -463,7 +462,7 @@ fn im(_: VmArgs, args: Vec<Value>) -> Result<Value> {
#[native_func(1)]
fn cis(_: VmArgs, args: Vec<Value>) -> Result<Value> {
let [value] = unpack_args!(args);
- match value.promote_trig() {
+ match value.floaty() {
Value::Float(f) => Ok(Value::Complex(Complex64::cis(f))),
Value::Complex(c) => Ok((Value::Complex(Complex64::cis(c.re)) * Value::Float((-c.im).exp()))?),
_ => error!("cis can only take floats")