Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_infinite, is_normal, is_subnormal, is_zero, is_nan to Float #336

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions z3/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ impl<'ctx> Float<'ctx> {
unop! {
unary_abs(Z3_mk_fpa_abs, Self);
unary_neg(Z3_mk_fpa_neg, Self);
is_infinite(Z3_mk_fpa_is_infinite, Bool<'ctx>);
is_normal(Z3_mk_fpa_is_normal, Bool<'ctx>);
is_subnormal(Z3_mk_fpa_is_subnormal, Bool<'ctx>);
is_zero(Z3_mk_fpa_is_zero, Bool<'ctx>);
is_nan(Z3_mk_fpa_is_nan, Bool<'ctx>);
}
binop! {
lt(Z3_mk_fpa_lt, Bool<'ctx>);
Expand Down
50 changes: 50 additions & 0 deletions z3/tests/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ fn test_float32_ops() {
};
}
test_unary_op!(-);

let solver = Solver::new(&ctx);

// Infinite
solver.check_assumptions(&[Float::from_f32(&ctx, f32::INFINITY).is_infinite()]);
twizmwazin marked this conversation as resolved.
Show resolved Hide resolved
solver.check_assumptions(&[Float::from_f32(&ctx, f32::NEG_INFINITY).is_infinite()]);
solver.check_assumptions(&[Float::from_f32(&ctx, 0f32).is_infinite().not()]);

// Normal
solver.check_assumptions(&[Float::from_f32(&ctx, 1f32).is_normal()]);
solver.check_assumptions(&[Float::from_f32(&ctx, f32::MIN_POSITIVE / 2.0)
.is_normal()
.not()]);

// Subnormal
solver.check_assumptions(&[Float::from_f32(&ctx, f32::MIN_POSITIVE / 2.0).is_subnormal()]);
solver.check_assumptions(&[Float::from_f32(&ctx, 1f32).is_subnormal().not()]);

// Zero
solver.check_assumptions(&[Float::from_f32(&ctx, 0f32).is_zero()]);
solver.check_assumptions(&[Float::from_f32(&ctx, 1f32).is_zero().not()]);

// NaN
solver.check_assumptions(&[Float::from_f32(&ctx, f32::NAN).is_nan()]);
solver.check_assumptions(&[Float::from_f32(&ctx, 1f32).is_nan().not()]);
}

#[test]
Expand All @@ -150,6 +175,31 @@ fn test_double_ops() {
};
}
test_unary_op!(-);

let solver = Solver::new(&ctx);

// Infinite
solver.check_assumptions(&[Float::from_f64(&ctx, f64::INFINITY).is_infinite()]);
solver.check_assumptions(&[Float::from_f64(&ctx, f64::NEG_INFINITY).is_infinite()]);
solver.check_assumptions(&[Float::from_f64(&ctx, 0f64).is_infinite().not()]);

// Normal
solver.check_assumptions(&[Float::from_f64(&ctx, 1f64).is_normal()]);
solver.check_assumptions(&[Float::from_f64(&ctx, f64::MIN_POSITIVE / 2.0)
.is_normal()
.not()]);

// Subnormal
solver.check_assumptions(&[Float::from_f64(&ctx, f64::MIN_POSITIVE / 2.0).is_subnormal()]);
solver.check_assumptions(&[Float::from_f64(&ctx, 1f64).is_subnormal().not()]);

// Zero
solver.check_assumptions(&[Float::from_f64(&ctx, 0f64).is_zero()]);
solver.check_assumptions(&[Float::from_f64(&ctx, 1f64).is_zero().not()]);

// NaN
solver.check_assumptions(&[Float::from_f64(&ctx, f64::NAN).is_nan()]);
solver.check_assumptions(&[Float::from_f64(&ctx, 1f64).is_nan().not()]);
}

#[test]
Expand Down