-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
30 lines (23 loc) · 892 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include "ieee-packing.hpp"
int main(int, char**)
{
//
std::cout << "\nieee754 float packing example!\n\n";
double value = M_PI;
auto packed = pack_f64(value);
auto unpacked = unpack_f64(packed);
printf(" Number is: %f\n", value);
printf(" Number (hex): %a\n", value);
printf(" Packed value: 0x%016lx\n", packed);
printf(" Unpacked (hex): %a\n", unpacked);
printf(" Error: %a\n", fabs(value - unpacked));
std::cout << "\n"
<< " Packing and unpacking worked with denomralized \n"
<< " numbers; however, it is also limited by the \n"
<< " precision of std::frexp and std::ldexp.\n"
<< " Therefore, do NOT expect precision better than\n"
<< " std::numeric_limits<T>::epsilon().\n"
<< "\n";
return EXIT_SUCCESS;
}