BAM
Abstract Machine for Bottom-Up Evaluation with the Push Method
Macros
idiv.h File Reference

Macros for rounded integer division and percent. More...

#include "../base/ver.h"
#include "../base/check.h"

Go to the source code of this file.

Macros

#define IDIV_ROUND(X, Y)   (((X)+(Y)/2)/(Y))
 
#define IDIV_CEILING(X, Y)   (((X)+(Y)-1)/(Y))
 
#define IDIV_WHOLE(X, Y)   ((((X)*10+(Y)/2)/(Y))/10)
 
#define IDIV_TENTH(X, Y)   (((((X)-IDIV_WHOLE((X),(Y))*(Y)) * 10 + (Y)/2)) / (Y))
 
#define IDIV_PERCENT(X, Y)   (((X)*100+((Y)/2))/(Y))
 

Detailed Description

Macros for rounded integer division and percent.

Macro Definition Documentation

#define IDIV_CEILING (   X,
 
)    (((X)+(Y)-1)/(Y))

Integer division, round up.

Note that this works only for non-negative numbers.

#define IDIV_PERCENT (   X,
 
)    (((X)*100+((Y)/2))/(Y))

Compute Percentage, round result.

#define IDIV_ROUND (   X,
 
)    (((X)+(Y)/2)/(Y))

Integer division, round result

Note that this works only for non-negative numbers.

#define IDIV_TENTH (   X,
 
)    (((((X)-IDIV_WHOLE((X),(Y))*(Y)) * 10 + (Y)/2)) / (Y))

Integer division with one decimal place, tenth.

Note that this works only for non-negative numbers.

#define IDIV_WHOLE (   X,
 
)    ((((X)*10+(Y)/2)/(Y))/10)

Integer division with one decimal place, whole part.

Note that this works only for non-negative numbers.