mirror of
https://github.com/ksherlock/mpw.git
synced 2025-02-19 17:30:32 +00:00
testing -- static constants so long double padding is deterministic.
This commit is contained in:
parent
9a98bb40b6
commit
d0fa609c46
@ -34,6 +34,16 @@ namespace floating_point {
|
||||
void reverse_bytes_if(void *vp, std::false_type) {
|
||||
}
|
||||
|
||||
#if 0
|
||||
enum classification {
|
||||
zero,
|
||||
infinite,
|
||||
quiet_nan,
|
||||
signaling_nan,
|
||||
normal,
|
||||
subnormal
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace single_traits {
|
||||
constexpr size_t bias = 127;
|
||||
@ -114,6 +124,7 @@ namespace floating_point {
|
||||
bool nan = false;
|
||||
bool inf = false;
|
||||
|
||||
//classification type = zero;
|
||||
|
||||
template<class T, typename = std::enable_if<std::is_floating_point<T>::value> >
|
||||
void read(T x)
|
||||
@ -187,13 +198,11 @@ namespace floating_point {
|
||||
}
|
||||
|
||||
void write(format<12, endian::native>, void *vp) const {
|
||||
// todo -- padding?
|
||||
write_extended(vp);
|
||||
std::memset((uint8_t *)vp + 10, 0, 12-10);
|
||||
}
|
||||
|
||||
void write(format<16, endian::native>, void *vp) const {
|
||||
// todo -- padding?
|
||||
write_extended(vp);
|
||||
std::memset((uint8_t *)vp + 10, 0, 16-10);
|
||||
}
|
||||
@ -207,16 +216,7 @@ namespace floating_point {
|
||||
info() = default;
|
||||
|
||||
|
||||
#if 0
|
||||
enum {
|
||||
fp_zero,
|
||||
fp_infinite,
|
||||
fp_quiet_nan,
|
||||
fp_signaling_nan,
|
||||
fp_normal,
|
||||
fp_subnormal
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <inttypes.h>
|
||||
|
||||
namespace fp = floating_point;
|
||||
|
||||
@ -26,6 +27,19 @@ void bitdump(const void *vp, unsigned bytes) {
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void print(const fp::info &fpi) {
|
||||
|
||||
printf("sign: %d\n", fpi.sign);
|
||||
printf("one : %d\n", fpi.one);
|
||||
printf("exp : %d\n", fpi.exp);
|
||||
printf("sig : %" PRIx64 "\n", fpi.sig);
|
||||
bitdump(&fpi.sig, 8);
|
||||
printf("nan : %d\n", (int)fpi.nan);
|
||||
printf("inf : %d\n", (int)fpi.inf);
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE( "1.0 is handled", "[floating point info]") {
|
||||
|
||||
@ -191,9 +205,10 @@ TEST_CASE( "Inf is handled", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast 0.0", "[floating point info]") {
|
||||
|
||||
float target_f = 0.0;
|
||||
double target_d = 0.0;
|
||||
double target_ld = 0.0;
|
||||
static const float target_f = 0.0;
|
||||
static const double target_d = 0.0;
|
||||
static const long double target_ld = 0.0;
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -204,6 +219,8 @@ TEST_CASE( "Re-cast 0.0", "[floating point info]") {
|
||||
fpi.write(d);
|
||||
fpi.write(ld);
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
@ -213,9 +230,10 @@ TEST_CASE( "Re-cast 0.0", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast 1.0", "[floating point info]") {
|
||||
|
||||
float target_f = 1.0;
|
||||
double target_d = 1.0;
|
||||
double target_ld = 1.0;
|
||||
static const float target_f = 1.0;
|
||||
static const double target_d = 1.0;
|
||||
static const long double target_ld = 1.0;
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -226,6 +244,8 @@ TEST_CASE( "Re-cast 1.0", "[floating point info]") {
|
||||
fpi.write(d);
|
||||
fpi.write(ld);
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
@ -235,9 +255,10 @@ TEST_CASE( "Re-cast 1.0", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast -1.0", "[floating point info]") {
|
||||
|
||||
float target_f = -1.0;
|
||||
double target_d = -1.0;
|
||||
double target_ld = -1.0;
|
||||
static const float target_f = -1.0;
|
||||
static const double target_d = -1.0;
|
||||
static const long double target_ld = -1.0;
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -248,6 +269,8 @@ TEST_CASE( "Re-cast -1.0", "[floating point info]") {
|
||||
fpi.write(d);
|
||||
fpi.write(ld);
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
@ -258,9 +281,10 @@ TEST_CASE( "Re-cast -1.0", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast 1000.0", "[floating point info]") {
|
||||
|
||||
float target_f = 1000.0;
|
||||
double target_d = 1000.0;
|
||||
double target_ld = 1000.0;
|
||||
static const float target_f = 1000.0;
|
||||
static const double target_d = 1000.0;
|
||||
static const long double target_ld = 1000.0;
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -271,6 +295,8 @@ TEST_CASE( "Re-cast 1000.0", "[floating point info]") {
|
||||
fpi.write(d);
|
||||
fpi.write(ld);
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
@ -281,9 +307,10 @@ TEST_CASE( "Re-cast 1000.0", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast Inf", "[floating point info]") {
|
||||
|
||||
float target_f = 1.0/0.0;
|
||||
double target_d = 1.0/0.0;
|
||||
double target_ld = 1.0/0.0;
|
||||
static const float target_f = 1.0/0.0;
|
||||
static const double target_d = 1.0/0.0;
|
||||
static const long double target_ld = 1.0/0.0;
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -294,6 +321,8 @@ TEST_CASE( "Re-cast Inf", "[floating point info]") {
|
||||
fpi.write(d);
|
||||
fpi.write(ld);
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
@ -303,9 +332,10 @@ TEST_CASE( "Re-cast Inf", "[floating point info]") {
|
||||
|
||||
TEST_CASE( "Re-cast NaN", "[floating point info]") {
|
||||
|
||||
float target_f = nanf("16");
|
||||
double target_d = nan("16");
|
||||
double target_ld = nanl("16");
|
||||
static const float target_f = nanf("16");
|
||||
static const double target_d = nan("16");
|
||||
static const long double target_ld = nanl("16");
|
||||
|
||||
long double ld;
|
||||
double d;
|
||||
float f;
|
||||
@ -317,6 +347,9 @@ TEST_CASE( "Re-cast NaN", "[floating point info]") {
|
||||
fpi.write(ld);
|
||||
|
||||
|
||||
//bitdump(&ld, sizeof(ld));
|
||||
//bitdump(&target_ld, sizeof(target_ld));
|
||||
|
||||
REQUIRE(memcmp(&target_f, &f, sizeof(f)) == 0);
|
||||
REQUIRE(memcmp(&target_d, &d, sizeof(d)) == 0);
|
||||
REQUIRE(memcmp(&target_ld, &ld, sizeof(ld)) == 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user