forked from ROCm/MIOpen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcerr.hpp
34 lines (31 loc) · 1.08 KB
/
calcerr.hpp
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
31
32
33
34
#ifndef GUARD_CALC_ERR_
#define GUARD_CALC_ERR_
template <typename _T>
double CalcErr(_T c_val, _T g_val)
{
double err = -1.0;
if(sizeof(_T) == 2)
{
int16_t* c_uval = reinterpret_cast<int16_t*>(&c_val);
int16_t* g_uval = reinterpret_cast<int16_t*>(&g_val);
err = static_cast<double>(std::abs(*c_uval - *g_uval));
}
else if(sizeof(_T) == 4)
{
int32_t* c_uval = reinterpret_cast<int32_t*>(&c_val);
int32_t* g_uval = reinterpret_cast<int32_t*>(&g_val);
err = static_cast<double>(std::abs(*c_uval - *g_uval));
}
else if(sizeof(_T) == 8)
{
int64_t* c_uval = reinterpret_cast<int64_t*>(&c_val);
int64_t* g_uval = reinterpret_cast<int64_t*>(&g_val);
err = static_cast<double>(std::abs(*c_uval - *g_uval));
}
// double delta = abs(c_val - g_val);
// double nextafter_delta = nextafterf(min(abs(c_val), abs(g_val)), (_T)INFINITY) -
// min(abs(c_val), abs(g_val));
// err = delta / nextafter_delta;
return err;
}
#endif // GUARD_GUARD_CALC_ERR_