Float function isPositive, isNegative, and isZero

This commit is contained in:
Chad Stearns 2020-05-22 23:05:17 -04:00
parent 3269b6ed1e
commit c83a6dc7b8
5 changed files with 130 additions and 28 deletions

View file

@ -37,9 +37,69 @@ pub fn builtin_defs(var_store: &VarStore) -> Vec<Def> {
int_is_zero(var_store),
int_is_positive(var_store),
int_is_negative(var_store),
float_is_positive(var_store),
float_is_negative(var_store),
float_is_zero(var_store),
]
}
/// Float.isZero : Float -> Bool
fn float_is_zero(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
defn(
Symbol::FLOAT_IS_ZERO,
vec![Symbol::FLOAT_IS_ZERO_ARG],
var_store,
call(
Symbol::FLOAT_EQ,
vec![
Float(var_store.fresh(), 0.0),
Var(Symbol::FLOAT_IS_ZERO_ARG),
],
var_store,
),
)
}
/// Float.isNegative : Float -> Bool
fn float_is_negative(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
defn(
Symbol::FLOAT_IS_NEGATIVE,
vec![Symbol::FLOAT_IS_NEGATIVE_ARG],
var_store,
call(
Symbol::FLOAT_GT,
vec![
Float(var_store.fresh(), 0.0),
Var(Symbol::FLOAT_IS_NEGATIVE_ARG),
],
var_store,
),
)
}
/// Float.isPositive : Float -> Bool
fn float_is_positive(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;
defn(
Symbol::FLOAT_IS_POSITIVE,
vec![Symbol::FLOAT_IS_POSITIVE_ARG],
var_store,
call(
Symbol::FLOAT_GT,
vec![
Var(Symbol::FLOAT_IS_POSITIVE_ARG),
Float(var_store.fresh(), 0.0),
],
var_store,
),
)
}
/// Int.isNegative : Int -> Bool
fn int_is_negative(var_store: &VarStore) -> Def {
use crate::expr::Expr::*;