cyclone/include/cyclone
Yorick Hardy 4bbceeb4d6 round half-integers to even instead of away from zero
This changes the behaviour to match r7rs (round x) instead of C round(x).

An answer to https://stackoverflow.com/questions/32746523/ieee-754-compliant-round-half-to-even
suggests using remainder(). The following will work if FE_TONEAREST is defined, but C11
requires FE_TONEAREST to be defined if and only if the implemenetation supports it in
fegetround() and fesetround() [Draft N1570]. On the other hand, remainder() must be defined.
C23 will have roundeven(), but this is not yet available on all platforms.
The behaviour of remainder is described in Draft N1570, page 254, footnote 239.

Alternative implementation:

  double round_to_nearest_even(double x)
  {
  #pragma STDC FENV_ACCESS ON
    int mode;
    double nearest;
    mode = fegetround();
    fesetround(FE_TONEAREST);
    nearest = nearbyint(x);
    fesetround(mode);
  #pragma STDC FENV_ACCESS OFF
    return nearest;
  }
2024-02-01 22:25:47 +02:00
..
bignum.h Re-format code 2024-01-17 19:43:47 -08:00
ck_ht_hash.h Remove unnecesary include 2017-01-11 22:17:26 -05:00
hashset.h Re-format code 2024-01-17 19:43:47 -08:00
runtime-main.h Re-format code 2024-01-17 19:43:47 -08:00
runtime.h round half-integers to even instead of away from zero 2024-02-01 22:25:47 +02:00
types.h Re-format code 2024-01-17 19:43:47 -08:00