mirror of
https://github.com/reactos/reactos.git
synced 2024-11-20 06:15:26 +00:00
435a566751
* sumatrapdf - vendor import * everything compiles (libjpeg, poppler, fitz, sumatrapdf) * does NOT link (remove the comment tags in the parent directory.rbuild file (rosapps dir) to build it) svn path=/trunk/; revision=29295
150 lines
5.4 KiB
C++
150 lines
5.4 KiB
C++
//========================================================================
|
|
//
|
|
// FixedPoint.h
|
|
//
|
|
// Fixed point type, with C++ operators.
|
|
//
|
|
// Copyright 2004 Glyph & Cog, LLC
|
|
//
|
|
//========================================================================
|
|
|
|
#ifndef FIXEDPOINT_H
|
|
#define FIXEDPOINT_H
|
|
|
|
#include <config.h>
|
|
|
|
#if USE_FIXEDPOINT
|
|
|
|
#ifdef USE_GCC_PRAGMAS
|
|
#pragma interface
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define fixptShift 16
|
|
#define fixptMaskL ((1 << fixptShift) - 1)
|
|
#define fixptMaskH (~fixptMaskL)
|
|
|
|
typedef long long FixPtInt64;
|
|
|
|
class FixedPoint {
|
|
public:
|
|
|
|
FixedPoint() { val = 0; }
|
|
FixedPoint(const FixedPoint &x) { val = x.val; }
|
|
FixedPoint(double x) { val = (int)(x * (1 << fixptShift) + 0.5); }
|
|
FixedPoint(int x) { val = x << fixptShift; }
|
|
FixedPoint(long x) { val = x << fixptShift; }
|
|
|
|
operator float()
|
|
{ return (float) val * ((float)1 / (float)(1 << fixptShift)); }
|
|
operator double()
|
|
{ return (double) val * (1.0 / (double)(1 << fixptShift)); }
|
|
operator int()
|
|
{ return val >> fixptShift; }
|
|
|
|
int getRaw() { return val; }
|
|
|
|
FixedPoint operator =(FixedPoint x) { val = x.val; return *this; }
|
|
|
|
int operator ==(FixedPoint x) { return val == x.val; }
|
|
int operator ==(double x) { return *this == (FixedPoint)x; }
|
|
int operator ==(int x) { return *this == (FixedPoint)x; }
|
|
int operator ==(long x) { return *this == (FixedPoint)x; }
|
|
|
|
int operator !=(FixedPoint x) { return val != x.val; }
|
|
int operator !=(double x) { return *this != (FixedPoint)x; }
|
|
int operator !=(int x) { return *this != (FixedPoint)x; }
|
|
int operator !=(long x) { return *this != (FixedPoint)x; }
|
|
|
|
int operator <(FixedPoint x) { return val < x.val; }
|
|
int operator <(double x) { return *this < (FixedPoint)x; }
|
|
int operator <(int x) { return *this < (FixedPoint)x; }
|
|
int operator <(long x) { return *this < (FixedPoint)x; }
|
|
|
|
int operator <=(FixedPoint x) { return val <= x.val; }
|
|
int operator <=(double x) { return *this <= (FixedPoint)x; }
|
|
int operator <=(int x) { return *this <= (FixedPoint)x; }
|
|
int operator <=(long x) { return *this <= (FixedPoint)x; }
|
|
|
|
int operator >(FixedPoint x) { return val > x.val; }
|
|
int operator >(double x) { return *this > (FixedPoint)x; }
|
|
int operator >(int x) { return *this > (FixedPoint)x; }
|
|
int operator >(long x) { return *this > (FixedPoint)x; }
|
|
|
|
int operator >=(FixedPoint x) { return val >= x.val; }
|
|
int operator >=(double x) { return *this >= (FixedPoint)x; }
|
|
int operator >=(int x) { return *this >= (FixedPoint)x; }
|
|
int operator >=(long x) { return *this >= (FixedPoint)x; }
|
|
|
|
FixedPoint operator -() { return make(-val); }
|
|
|
|
FixedPoint operator +(FixedPoint x) { return make(val + x.val); }
|
|
FixedPoint operator +(double x) { return *this + (FixedPoint)x; }
|
|
FixedPoint operator +(int x) { return *this + (FixedPoint)x; }
|
|
FixedPoint operator +(long x) { return *this + (FixedPoint)x; }
|
|
|
|
FixedPoint operator +=(FixedPoint x) { val = val + x.val; return *this; }
|
|
FixedPoint operator +=(double x) { return *this += (FixedPoint)x; }
|
|
FixedPoint operator +=(int x) { return *this += (FixedPoint)x; }
|
|
FixedPoint operator +=(long x) { return *this += (FixedPoint)x; }
|
|
|
|
FixedPoint operator -(FixedPoint x) { return make(val - x.val); }
|
|
FixedPoint operator -(double x) { return *this - (FixedPoint)x; }
|
|
FixedPoint operator -(int x) { return *this - (FixedPoint)x; }
|
|
FixedPoint operator -(long x) { return *this - (FixedPoint)x; }
|
|
|
|
FixedPoint operator -=(FixedPoint x) { val = val - x.val; return *this; }
|
|
FixedPoint operator -=(double x) { return *this -= (FixedPoint)x; }
|
|
FixedPoint operator -=(int x) { return *this -= (FixedPoint)x; }
|
|
FixedPoint operator -=(long x) { return *this -= (FixedPoint)x; }
|
|
|
|
FixedPoint operator *(FixedPoint x) { return make(mul(val, x.val)); }
|
|
FixedPoint operator *(double x) { return *this * (FixedPoint)x; }
|
|
FixedPoint operator *(int x) { return *this * (FixedPoint)x; }
|
|
FixedPoint operator *(long x) { return *this * (FixedPoint)x; }
|
|
|
|
FixedPoint operator *=(FixedPoint x) { val = mul(val, x.val); return *this; }
|
|
FixedPoint operator *=(double x) { return *this *= (FixedPoint)x; }
|
|
FixedPoint operator *=(int x) { return *this *= (FixedPoint)x; }
|
|
FixedPoint operator *=(long x) { return *this *= (FixedPoint)x; }
|
|
|
|
FixedPoint operator /(FixedPoint x) { return make(div(val, x.val)); }
|
|
FixedPoint operator /(double x) { return *this / (FixedPoint)x; }
|
|
FixedPoint operator /(int x) { return *this / (FixedPoint)x; }
|
|
FixedPoint operator /(long x) { return *this / (FixedPoint)x; }
|
|
|
|
FixedPoint operator /=(FixedPoint x) { val = div(val, x.val); return *this; }
|
|
FixedPoint operator /=(double x) { return *this /= (FixedPoint)x; }
|
|
FixedPoint operator /=(int x) { return *this /= (FixedPoint)x; }
|
|
FixedPoint operator /=(long x) { return *this /= (FixedPoint)x; }
|
|
|
|
static FixedPoint abs(FixedPoint x) { return make(::abs(x.val)); }
|
|
|
|
static int floor(FixedPoint x) { return x.val >> fixptShift; }
|
|
|
|
static int ceil(FixedPoint x)
|
|
{ return (x.val & fixptMaskL) ? ((x.val >> fixptShift) + 1)
|
|
: (x.val >> fixptShift); }
|
|
|
|
static int round(FixedPoint x)
|
|
{ return (x.val + (1 << (fixptShift - 1))) >> fixptShift; }
|
|
|
|
static FixedPoint sqrt(FixedPoint x);
|
|
|
|
static FixedPoint pow(FixedPoint x, FixedPoint y);
|
|
|
|
private:
|
|
|
|
static FixedPoint make(int valA) { FixedPoint x; x.val = valA; return x; }
|
|
|
|
static int mul(int x, int y);
|
|
static int div(int x, int y);
|
|
|
|
int val; // 16.16 fixed point
|
|
};
|
|
|
|
#endif // USE_FIXEDPOINT
|
|
|
|
#endif
|