Skip to content

Commit

Permalink
Check fract on float for integer? (#214)
Browse files Browse the repository at this point in the history
* check fract on float for integer?

* adjust tests to accommodate new behavior

* fix exact-integer
  • Loading branch information
mattwparas authored May 19, 2024
1 parent 03c2d81 commit b88eb89
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 223 deletions.
8 changes: 6 additions & 2 deletions crates/steel-core/src/primitives/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ fn rationalp(value: &SteelVal) -> bool {
/// ```
#[steel_derive::function(name = "int?", constant = true)]
fn intp(value: &SteelVal) -> bool {
matches!(value, SteelVal::IntV(_) | SteelVal::BigNum(_))
match value {
SteelVal::IntV(_) | SteelVal::BigNum(_) => true,
SteelVal::NumV(n) if n.fract() == 0.0 => true,
_ => false,
}
}

/// Checks if the given value is an integer, an alias for `int?`
Expand Down Expand Up @@ -147,7 +151,7 @@ fn integerp(value: &SteelVal) -> bool {
/// ```
#[steel_derive::function(name = "exact-integer?", constant = true)]
fn exact_integerp(value: &SteelVal) -> bool {
intp(value)
matches!(value, SteelVal::IntV(_) | SteelVal::BigNum(_))
}

/// Checks if the given value is a floating-point number
Expand Down
2 changes: 1 addition & 1 deletion crates/steel-core/src/steel_vm/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ mod contract_tests {
let script = r#"
(define/contract (output)
(->/c (->/c string? int?))
(lambda (x) 10.0))
(lambda (x) 10.1))
(define/contract (accept)
(->/c (->/c string? number?))
Expand Down
Loading

0 comments on commit b88eb89

Please sign in to comment.