diff options
Diffstat (limited to 'src/H5Zscaleoffset.c')
-rw-r--r-- | src/H5Zscaleoffset.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 1cca9b1..91a6c00 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -667,6 +667,58 @@ H5Z_class2_t H5Z_SCALEOFFSET[1] = {{ H5Z_scaleoffset_modify_4(i, type, pow_fun, buf, d_nelmts, min, D_val) \ } +/* Include our own rounding routine and alias it to the stdc macros, if they + * aren't available. + */ +#if !(defined(H5_HAVE_LLROUND) && defined(H5_HAVE_LLROUNDF) && defined(H5_HAVE_LROUND) && defined(H5_HAVE_LROUNDF) && defined(H5_HAVE_ROUND) && defined(H5_HAVE_ROUNDF)) +/* Round a floating-point value to the nearest integer value 4/19/05 */ +/* rounding to the bigger absolute value if val is in the middle, + 0.5 -> 1, -0.5 ->-1 +5/9/05, KY */ +static double +H5Z__scaleoffset_rnd(double val) +{ + double u_val, l_val; + + u_val = HDceil(val); + l_val = HDfloor(val); + + if(val > 0) { + if((u_val - val) <= (val - l_val)) + return u_val; + else + return l_val; + } /* end if */ + else { + if((val - l_val) <= (u_val - val)) + return l_val; + else + return u_val; + } +} /* H5Z__scaleoffset_rnd() */ + +/* Alias rounding macros to routine above, if not defined */ +#if !defined(H5_HAVE_LLROUND) +#define llround(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LLROUND) */ +#if !defined(H5_HAVE_LLROUNDF) +#define llroundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LLROUNDF) */ +#if !defined(H5_HAVE_LROUND) +#define lround(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LROUND) */ +#if !defined(H5_HAVE_LROUNDF) +#define lroundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_LROUNDF) */ +#if !defined(H5_HAVE_ROUND) +#define round(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_ROUND) */ +#if !defined(H5_HAVE_ROUNDF) +#define roundf(x) H5Z__scaleoffset_rnd(x) +#endif /* !defined(H5_HAVE_ROUNDF) */ + +#endif /* !(defined(H5_HAVE_LLROUND) && defined(H5_HAVE_LLROUNDF) && defined(H5_HAVE_LROUND) && defined(H5_HAVE_LROUNDF) && defined(H5_HAVE_ROUND) && defined(H5_HAVE_ROUNDF)) */ + /*------------------------------------------------------------------------- * Function: H5Z_can_apply_scaleoffset |