next up previous contents index
次へ: Text 上へ: Data Types 戻る: Integer Type   目次   索引

Fixed-point Type

SANE_Fixed is used for variables that can take fixed point values in the range $-32768$ to $32767.9999$ with a resolution of $1/65535$. The C declarations relating to this type are given below.

#define SANE_FIXED_SCALE_SHIFT  16
typedef SANE_Word SANE_Fixed;
The macro SANE_FIXED_SCALE_SHIFT gives the location of the fixed binary point. This standard defines that value to be 16, which yields a resolution of $1/65536$.

Note that SANE_Fixed is simply an alias of SANE_Word. It is therefore always legal to use the latter type in place of the former. However, for clarity, it is recommended to use SANE_Fixed whenever a given variable or formal argument has a fixed interpretation as a fixed-point object.

For convenience, SANE also defines two macros that convert fixed-point values to and from C double floating point values.

SANE_FIX(d):
Returns the largest SANE fixed-point value that is smaller than the double value d. No range checking is performed. If the value of d is out of range, the result is undefined.

SANE_UNFIX(w):
Returns the nearest double machine number that corresponds to fixed-point value w.

SANE does not require that the following two expressions hold true (even if the values of w and d are in range):
SANE_UNFIX(SANE_FIX(d)) == d
SANE_FIX(SANE_UNFIX(w)) == w
In other words, conversion between fixed and double values may be lossy. It is therefore recommended to avoid repeated conversions between the two representations.


next up previous contents index
次へ: Text 上へ: Data Types 戻る: Integer Type   目次   索引
MATSUBAYASHI 'Shaolin' Kohji 平成14年10月29日