3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-09 10:51:50 +00:00
z3/test/hwf.cpp
Leonardo de Moura 68269c43a6 other components
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
2012-10-02 11:48:48 -07:00

118 lines
2.1 KiB
C++

/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
hwf.cpp
Abstract:
hwf repros...
Author:
Leonardo de Moura (leonardo) 2012-08-23.
Revision History:
--*/
#include"hwf.h"
#include"f2n.h"
#include"rational.h"
static void bug_set_double() {
hwf_manager m;
hwf a;
m.set(a, 0.1);
SASSERT(m.is_regular(a));
m.set(a, 1.1);
SASSERT(m.is_regular(a));
m.set(a, 11.3);
SASSERT(m.is_regular(a));
m.set(a, 0.0);
SASSERT(m.is_regular(a));
}
static void bug_to_rational() {
hwf_manager m;
hwf a;
unsynch_mpq_manager mq;
scoped_mpq r(mq);
double ad, rd;
m.set(a, 0.0);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, 1.0);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, 1.5);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, 0.875);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, -1.0);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, -1.5);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, -0.875);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
SASSERT(ad == rd);
m.set(a, 0.1);
m.to_rational(a, r);
ad = m.to_double(a);
rd = mq.get_double(r);
double diff = (ad-rd);
#ifdef _WINDOWS
// CMW: This one depends on the rounding mode,
// which is implicit in both hwf::set and in mpq::to_double.
SASSERT(diff >= -DBL_EPSILON && diff <= DBL_EPSILON);
#endif
}
static void bug_is_int() {
unsigned raw_val[2] = { 2147483648, 1077720461 };
double val = *(double*)(raw_val);
std::cout << val << "\n";
hwf_manager m;
hwf a;
m.set(a, val);
SASSERT(!m.is_int(a));
}
void tst_hwf() {
bug_is_int();
bug_set_double();
bug_to_rational();
}