lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make error on CVS


From: Heikki Johannes Junes
Subject: Re: make error on CVS
Date: Mon, 28 Jul 2003 01:02:34 +0300 (EEST)

>      #include <math.h>
>      [..]
>      double round(double x);

For fun,

/*
   ABS:    absolute value
   SIGN:   sign as 1.0 or -1.0
   FIX:    drop non-integer part
   ROUNDI: round: at 0.5 to 0.0, at -0.5 to  0.0, i.e. inwards
   ROUNDO: round: at 0.5 to 1.0, at -0.5 to -1.0, i.e. outwards
   ROUND:  round: at 0.5 to 1.0, at -0.5 to  0.0, i.e. upwards
*/
#define ABS(x) ( ( (x) >= 0 ) ? (x) : -(x) )
#define SIGN(x) ( ( (x) >= 0 ) ? 1.0 : -1.0 )
#define FIX(x) ( (double) ( (int) (x) ) )
#define ROUNDI(x) ( ABS( (x) - FIX(x) ) <= 0.5 ? FIX(x) : FIX( (x) + SIGN(x) ) )
#define ROUNDO(x) ( ABS( (x) - FIX(x) ) < 0.5 ? FIX(x) : FIX( (x) + SIGN(x) ) )
#define ROUND(x) ( ( (x) >= 0 ) ? ROUNDO(x) : ROUNDI(x) )

int main(void) {
  double x;

  printf( "   x   S(x)  F(x)  A(x) RI(x) RO(x)  R(x) \n" );
  for (x = -1.0; x <= 1.0; x = x + 0.25) {
    printf( "%5.2f %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f\n",
            x, SIGN(x), FIX(x), ABS(x), ROUNDI(x), ROUNDO(x), ROUND(x) );
  }
}

Greetings,

  Heikki Junes




reply via email to

[Prev in Thread] Current Thread [Next in Thread]