feat: Float from big numbers
This commit is contained in:
parent
f66039f7f0
commit
8e84a8c9ec
3 changed files with 13 additions and 1 deletions
|
|
@ -77,6 +77,7 @@ public:
|
|||
unsigned long int get_unsigned_long_int() const { lean_assert(is_unsigned_long_int()); return mpz_get_ui(m_val); }
|
||||
unsigned int get_unsigned_int() const { lean_assert(is_unsigned_int()); return static_cast<unsigned>(get_unsigned_long_int()); }
|
||||
size_t get_size_t() const;
|
||||
double get_double() const { return mpz_get_d(m_val); }
|
||||
|
||||
mpz & operator=(mpz const & v) { mpz_set(m_val, v.m_val); return *this; }
|
||||
mpz & operator=(mpz && v) { swap(*this, v); return *this; }
|
||||
|
|
|
|||
|
|
@ -1453,7 +1453,7 @@ extern "C" double lean_float_of_nat(b_lean_obj_arg a) {
|
|||
if (lean_is_scalar(a)) {
|
||||
return static_cast<double>(lean_unbox(a));
|
||||
} else {
|
||||
return std::nan(""); // TODO(Leo): improve
|
||||
return mpz_value(a).get_double();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
11
tests/lean/run/float_from_bignum.lean
Normal file
11
tests/lean/run/float_from_bignum.lean
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def check (b : Bool) : IO Unit :=
|
||||
unless b $ throw $ IO.userError "check failed"
|
||||
|
||||
def tst1 : IO Unit := do
|
||||
check (Nat.toFloat (10^40) > Nat.toFloat (10^30));
|
||||
check (Nat.toFloat (10^40) >= Nat.toFloat (10^30));
|
||||
check (Nat.toFloat (10^40) == Nat.toFloat (10^40));
|
||||
check (Nat.toFloat (10^80) > Nat.toFloat (10^40));
|
||||
pure ()
|
||||
|
||||
#eval tst1
|
||||
Loading…
Add table
Reference in a new issue