JasPer  3.0.4
Fixed-Point Arithmetic

Fixed-Point Arithmetic. More...

Macros

#define JAS_FIX_ZERO(fix_t, fracbits)   JAS_INTTOFIX(fix_t, fracbits, 0)
 
#define JAS_FIX_ONE(fix_t, fracbits)   JAS_INTTOFIX(fix_t, fracbits, 1)
 
#define JAS_FIX_HALF(fix_t, fracbits)   (JAS_CAST(fix_t, 1) << ((fracbits) - 1))
 
#define JAS_INTTOFIX(fix_t, fracbits, x)   (JAS_CAST(fix_t, x) << (fracbits))
 
#define JAS_FIXTOINT(fix_t, fracbits, x)   JAS_CAST(int, (x) >> (fracbits))
 
#define JAS_FIXTODBL(fix_t, fracbits, x)   (JAS_CAST(double, x) / JAS_FIX_ONE(fix_t, fracbits))
 
#define JAS_DBLTOFIX(fix_t, fracbits, x)   JAS_CAST(fix_t, ((x) * JAS_CAST(double, JAS_FIX_ONE(fix_t, fracbits))))
 
#define JAS_FIX_ADD   JAS_FIX_ADD_FAST
 
#define JAS_FIX_ADD_FAST(fix_t, fracbits, x, y)   ((x) + (y))
 
#define JAS_FIX_ADD_OFLOW(fix_t, fracbits, x, y)
 
#define JAS_FIX_MUL   JAS_FIX_MUL_FAST
 
#define JAS_FIX_MUL_FAST(fix_t, fracbits, bigfix_t, x, y)
 
#define JAS_FIX_MUL_OFLOW(fix_t, fracbits, bigfix_t, x, y)
 
#define JAS_FIX_MULBYINT   JAS_FIX_MULBYINT_FAST
 
#define JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y)   JAS_CAST(fix_t, ((x) * (y)))
 
#define JAS_FIX_MULBYINT_OFLOW(fix_t, fracbits, x, y)   JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y)
 
#define JAS_FIX_DIV   JAS_FIX_DIV_FAST
 
#define JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y)   JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) << (fracbits)) / (y))
 
#define JAS_FIX_DIV_UFLOW(fix_t, fracbits, bigfix_t, x, y)   JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y)
 
#define JAS_FIX_NEG   JAS_FIX_NEG_FAST
 
#define JAS_FIX_NEG_FAST(fix_t, fracbits, x)   (-(x))
 
#define JAS_FIX_NEG_OFLOW(fix_t, fracbits, x)   (((x) < 0) ? (-(x) > 0 || JAS_FIX_OFLOW(), -(x)) : (-(x)))
 
#define JAS_FIX_ASL   JAS_FIX_ASL_FAST
 
#define JAS_FIX_ASL_FAST(fix_t, fracbits, x, n)   ((x) << (n))
 
#define JAS_FIX_ASL_OFLOW(fix_t, fracbits, x, n)   ((((x) << (n)) >> (n)) == (x) || JAS_FIX_OFLOW(), (x) << (n))
 
#define JAS_FIX_ASR   JAS_FIX_ASR_FAST
 
#define JAS_FIX_ASR_FAST(fix_t, fracbits, x, n)   ((x) >> (n))
 
#define JAS_FIX_ASR_UFLOW(fix_t, fracbits, x, n)   JAS_FIX_ASR_FAST(fix_t, fracbits, x, n)
 
#define JAS_FIX_SUB(fix_t, fracbits, x, y)   JAS_FIX_ADD(fix_t, fracbits, x, JAS_FIX_NEG(fix_t, fracbits, y))
 
#define JAS_FIX_PLUSEQ(fix_t, fracbits, x, y)   ((x) = JAS_FIX_ADD(fix_t, fracbits, x, y))
 
#define JAS_FIX_MINUSEQ(fix_t, fracbits, x, y)   ((x) = JAS_FIX_SUB(fix_t, fracbits, x, y))
 
#define JAS_FIX_MULEQ(fix_t, fracbits, bigfix_t, x, y)   ((x) = JAS_FIX_MUL(fix_t, fracbits, bigfix_t, x, y))
 
#define JAS_FIX_ABS(fix_t, fracbits, x)   (((x) >= 0) ? (x) : (JAS_FIX_NEG(fix_t, fracbits, x)))
 
#define JAS_FIX_ISINT(fix_t, fracbits, x)   (JAS_FIX_FLOOR(fix_t, fracbits, x) == (x))
 
#define JAS_FIX_SGN(fix_t, fracbits, x)   ((x) >= 0 ? 1 : (-1))
 
#define JAS_FIX_CMP(fix_t, fracbits, x, y)   ((x) > (y) ? 1 : (((x) == (y)) ? 0 : (-1)))
 
#define JAS_FIX_LT(fix_t, fracbits, x, y)   ((x) < (y))
 
#define JAS_FIX_LTE(fix_t, fracbits, x, y)   ((x) <= (y))
 
#define JAS_FIX_GT(fix_t, fracbits, x, y)   ((x) > (y))
 
#define JAS_FIX_GTE(fix_t, fracbits, x, y)   ((x) >= (y))
 
#define JAS_FIX_ROUND(fix_t, fracbits, x)
 
#define JAS_FIX_FLOOR(fix_t, fracbits, x)   ((x) & (~(JAS_FIX_ONE(fix_t, fracbits) - 1)))
 

Detailed Description

Fixed-Point Arithmetic.

Macro Definition Documentation

◆ JAS_DBLTOFIX

#define JAS_DBLTOFIX (   fix_t,
  fracbits,
 
)    JAS_CAST(fix_t, ((x) * JAS_CAST(double, JAS_FIX_ONE(fix_t, fracbits))))

Convert a double to a fixed-point number.

◆ JAS_FIX_ABS

#define JAS_FIX_ABS (   fix_t,
  fracbits,
 
)    (((x) >= 0) ? (x) : (JAS_FIX_NEG(fix_t, fracbits, x)))

Calculate the absolute value of a fixed-point number.

◆ JAS_FIX_ADD

#define JAS_FIX_ADD   JAS_FIX_ADD_FAST

Calculate the sum of two fixed-point numbers.

◆ JAS_FIX_ADD_FAST

#define JAS_FIX_ADD_FAST (   fix_t,
  fracbits,
  x,
 
)    ((x) + (y))

Calculate the sum of two fixed-point numbers without overflow checking.

◆ JAS_FIX_ADD_OFLOW

#define JAS_FIX_ADD_OFLOW (   fix_t,
  fracbits,
  x,
 
)
Value:
((x) >= 0) ? \
(((y) >= 0) ? ((x) + (y) >= 0 || JAS_FIX_OFLOW(), (x) + (y)) : \
((x) + (y))) : \
(((y) >= 0) ? ((x) + (y)) : ((x) + (y) < 0 || JAS_FIX_OFLOW(), \
(x) + (y)))

Calculate the sum of two fixed-point numbers with overflow checking.

◆ JAS_FIX_ASL

#define JAS_FIX_ASL   JAS_FIX_ASL_FAST

Perform an arithmetic shift left of a fixed-point number.

◆ JAS_FIX_ASL_FAST

#define JAS_FIX_ASL_FAST (   fix_t,
  fracbits,
  x,
 
)    ((x) << (n))

Perform an arithmetic shift left of a fixed-point number without overflow checking.

◆ JAS_FIX_ASL_OFLOW

#define JAS_FIX_ASL_OFLOW (   fix_t,
  fracbits,
  x,
 
)    ((((x) << (n)) >> (n)) == (x) || JAS_FIX_OFLOW(), (x) << (n))

Perform an arithmetic shift left of a fixed-point number with overflow checking.

◆ JAS_FIX_ASR

#define JAS_FIX_ASR   JAS_FIX_ASR_FAST

Perform an arithmetic shift right of a fixed-point number.

◆ JAS_FIX_ASR_FAST

#define JAS_FIX_ASR_FAST (   fix_t,
  fracbits,
  x,
 
)    ((x) >> (n))

Perform an arithmetic shift right of a fixed-point number without underflow checking.

◆ JAS_FIX_ASR_UFLOW

#define JAS_FIX_ASR_UFLOW (   fix_t,
  fracbits,
  x,
 
)    JAS_FIX_ASR_FAST(fix_t, fracbits, x, n)

Perform an arithmetic shift right of a fixed-point number with underflow checking.

◆ JAS_FIX_CMP

#define JAS_FIX_CMP (   fix_t,
  fracbits,
  x,
 
)    ((x) > (y) ? 1 : (((x) == (y)) ? 0 : (-1)))

Compare two fixed-point numbers.

◆ JAS_FIX_DIV

#define JAS_FIX_DIV   JAS_FIX_DIV_FAST

Calculate the quotient of two fixed-point numbers.

◆ JAS_FIX_DIV_FAST

#define JAS_FIX_DIV_FAST (   fix_t,
  fracbits,
  bigfix_t,
  x,
 
)    JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) << (fracbits)) / (y))

Calculate the quotient of two fixed-point numbers without underflow checking.

◆ JAS_FIX_DIV_UFLOW

#define JAS_FIX_DIV_UFLOW (   fix_t,
  fracbits,
  bigfix_t,
  x,
 
)    JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y)

Calculate the quotient of two fixed-point numbers with underflow checking.

◆ JAS_FIX_FLOOR

#define JAS_FIX_FLOOR (   fix_t,
  fracbits,
 
)    ((x) & (~(JAS_FIX_ONE(fix_t, fracbits) - 1)))

Round a fixed-point number to the nearest integer in the direction of negative infinity (i.e., the floor function).

◆ JAS_FIX_GT

#define JAS_FIX_GT (   fix_t,
  fracbits,
  x,
 
)    ((x) > (y))

Greater than.

◆ JAS_FIX_GTE

#define JAS_FIX_GTE (   fix_t,
  fracbits,
  x,
 
)    ((x) >= (y))

Greater than or equal.

◆ JAS_FIX_HALF

#define JAS_FIX_HALF (   fix_t,
  fracbits 
)    (JAS_CAST(fix_t, 1) << ((fracbits) - 1))

The representation of the value one half.

◆ JAS_FIX_ISINT

#define JAS_FIX_ISINT (   fix_t,
  fracbits,
 
)    (JAS_FIX_FLOOR(fix_t, fracbits, x) == (x))

Is a fixed-point number an integer?

◆ JAS_FIX_LT

#define JAS_FIX_LT (   fix_t,
  fracbits,
  x,
 
)    ((x) < (y))

Less than.

◆ JAS_FIX_LTE

#define JAS_FIX_LTE (   fix_t,
  fracbits,
  x,
 
)    ((x) <= (y))

Less than or equal.

◆ JAS_FIX_MINUSEQ

#define JAS_FIX_MINUSEQ (   fix_t,
  fracbits,
  x,
 
)    ((x) = JAS_FIX_SUB(fix_t, fracbits, x, y))

Subtract one fixed-point number from another.

◆ JAS_FIX_MUL

#define JAS_FIX_MUL   JAS_FIX_MUL_FAST

Calculate the product of two fixed-point numbers.

◆ JAS_FIX_MUL_FAST

#define JAS_FIX_MUL_FAST (   fix_t,
  fracbits,
  bigfix_t,
  x,
 
)
Value:
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y)) >> \
(fracbits))

Calculate the product of two fixed-point numbers without overflow checking.

◆ JAS_FIX_MUL_OFLOW

#define JAS_FIX_MUL_OFLOW (   fix_t,
  fracbits,
  bigfix_t,
  x,
 
)
Value:
((JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> (fracbits)) == \
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
(fracbits))) ? \
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
(fracbits))) : JAS_FIX_OFLOW())

Calculate the product of two fixed-point numbers with overflow checking.

◆ JAS_FIX_MULBYINT

#define JAS_FIX_MULBYINT   JAS_FIX_MULBYINT_FAST

Calculate the product of a fixed-point number and an int.

◆ JAS_FIX_MULBYINT_FAST

#define JAS_FIX_MULBYINT_FAST (   fix_t,
  fracbits,
  x,
 
)    JAS_CAST(fix_t, ((x) * (y)))

Calculate the product of a fixed-point number and an int without overflow checking.

◆ JAS_FIX_MULBYINT_OFLOW

#define JAS_FIX_MULBYINT_OFLOW (   fix_t,
  fracbits,
  x,
 
)    JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y)

Calculate the product of a fixed-point number and an int with overflow checking.

◆ JAS_FIX_MULEQ

#define JAS_FIX_MULEQ (   fix_t,
  fracbits,
  bigfix_t,
  x,
 
)    ((x) = JAS_FIX_MUL(fix_t, fracbits, bigfix_t, x, y))

Multiply one fixed-point number by another.

◆ JAS_FIX_NEG

#define JAS_FIX_NEG   JAS_FIX_NEG_FAST

Negate a fixed-point number.

◆ JAS_FIX_NEG_FAST

#define JAS_FIX_NEG_FAST (   fix_t,
  fracbits,
 
)    (-(x))

Negate a fixed-point number without overflow checking.

◆ JAS_FIX_NEG_OFLOW

#define JAS_FIX_NEG_OFLOW (   fix_t,
  fracbits,
 
)    (((x) < 0) ? (-(x) > 0 || JAS_FIX_OFLOW(), -(x)) : (-(x)))

Negate a fixed-point number with overflow checking.

◆ JAS_FIX_ONE

#define JAS_FIX_ONE (   fix_t,
  fracbits 
)    JAS_INTTOFIX(fix_t, fracbits, 1)

The representation of the value one.

◆ JAS_FIX_PLUSEQ

#define JAS_FIX_PLUSEQ (   fix_t,
  fracbits,
  x,
 
)    ((x) = JAS_FIX_ADD(fix_t, fracbits, x, y))

Add one fixed-point number to another.

◆ JAS_FIX_ROUND

#define JAS_FIX_ROUND (   fix_t,
  fracbits,
 
)
Value:
(((x) < 0) ? JAS_FIX_FLOOR(fix_t, fracbits, JAS_FIX_ADD(fix_t, fracbits, \
(x), JAS_FIX_HALF(fix_t, fracbits))) : \
JAS_FIX_NEG(fix_t, fracbits, JAS_FIX_FLOOR(fix_t, fracbits, \
JAS_FIX_ADD(fix_t, fracbits, (-(x)), JAS_FIX_HALF(fix_t, fracbits)))))

Round a fixed-point number to the nearest integer.

◆ JAS_FIX_SGN

#define JAS_FIX_SGN (   fix_t,
  fracbits,
 
)    ((x) >= 0 ? 1 : (-1))

Get the sign of a fixed-point number.

◆ JAS_FIX_SUB

#define JAS_FIX_SUB (   fix_t,
  fracbits,
  x,
 
)    JAS_FIX_ADD(fix_t, fracbits, x, JAS_FIX_NEG(fix_t, fracbits, y))

Calculate the difference between two fixed-point numbers.

◆ JAS_FIX_ZERO

#define JAS_FIX_ZERO (   fix_t,
  fracbits 
)    JAS_INTTOFIX(fix_t, fracbits, 0)

The representation of the value zero.

◆ JAS_FIXTODBL

#define JAS_FIXTODBL (   fix_t,
  fracbits,
 
)    (JAS_CAST(double, x) / JAS_FIX_ONE(fix_t, fracbits))

Convert a fixed-point number to a double.

◆ JAS_FIXTOINT

#define JAS_FIXTOINT (   fix_t,
  fracbits,
 
)    JAS_CAST(int, (x) >> (fracbits))

Convert a fixed-point number to an int.

◆ JAS_INTTOFIX

#define JAS_INTTOFIX (   fix_t,
  fracbits,
 
)    (JAS_CAST(fix_t, x) << (fracbits))

Convert an int to a fixed-point number.

JAS_FIX_ADD
#define JAS_FIX_ADD
Definition: jas_fix.h:138
JAS_FIX_FLOOR
#define JAS_FIX_FLOOR(fix_t, fracbits, x)
Definition: jas_fix.h:334
JAS_FIX_NEG
#define JAS_FIX_NEG
Definition: jas_fix.h:212
JAS_FIX_HALF
#define JAS_FIX_HALF(fix_t, fracbits)
Definition: jas_fix.h:103