blob: 6c0c52634eba99e3438d097171540373b242c745 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/sgl/SkFP.h
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef SkFP_DEFINED
19#define SkFP_DEFINED
20
21#include "SkMath.h"
22
23#ifdef SK_SCALAR_IS_FLOAT
24
25 typedef float SkFP;
26
27 #define SkScalarToFP(n) (n)
28 #define SkFPToScalar(n) (n)
29 #define SkIntToFP(n) SkIntToScalar(n)
30 #define SkFPRound(x) SkScalarRound(n)
31 #define SkFPCeil(x) SkScalarCeil(n)
32 #define SkFPFloor(x) SkScalarFloor(n)
33
34 #define SkFPNeg(x) (-(x))
35 #define SkFPAbs(x) SkScalarAbs(x)
36 #define SkFPAdd(a, b) ((a) + (b))
37 #define SkFPSub(a, b) ((a) - (b))
38 #define SkFPMul(a, b) ((a) * (b))
39 #define SkFPMulInt(a, n) ((a) * (n))
40 #define SkFPDiv(a, b) ((a) / (b))
41 #define SkFPDivInt(a, n) ((a) / (n))
42 #define SkFPInvert(x) SkScalarInvert(x)
43 #define SkFPSqrt(x) SkScalarSqrt(x)
44 #define SkFPCubeRoot(x) pow(x, 1.0f/3)
45
46 #define SkFPLT(a, b) ((a) < (b))
47 #define SkFPLE(a, b) ((a) <= (b))
48 #define SkFPGT(a, b) ((a) > (b))
49 #define SkFPGE(a, b) ((a) >= (b))
50
51#else // scalar is fixed
52
53 #include "SkFloat.h"
54
55 typedef int32_t SkFP;
56
57 #define SkScalarToFP(n) SkFloat::SetShift(n, -16)
58 #define SkFPToScalar(n) SkFloat::GetShift(n, -16)
59 #define SkIntToFP(n) SkFloat::SetShift(n, 0)
60 #define SkFPRound(x) SkFloat::Round(x);
61 #define SkFPCeil(x) SkFloat::Ceil();
62 #define SkFPFloor(x) SkFloat::Floor();
63
64 #define SkFPNeg(x) SkFloat::Neg(x)
65 #define SkFPAbs(x) SkFloat::Abs(x)
66 #define SkFPAdd(a, b) SkFloat::Add(a, b)
67 #define SkFPSub(a, b) SkFloat::Add(a, SkFloat::Neg(b))
68 #define SkFPMul(a, b) SkFloat::Mul(a, b)
69 #define SkFPMulInt(a, n) SkFloat::MulInt(a, n)
70 #define SkFPDiv(a, b) SkFloat::Div(a, b)
71 #define SkFPDivInt(a, n) SkFloat::DivInt(a, n)
72 #define SkFPInvert(x) SkFloat::Invert(x)
73 #define SkFPSqrt(x) SkFloat::Sqrt(x)
74 #define SkFPCubeRoot(x) SkFloat::CubeRoot(x)
75
76 #define SkFPLT(a, b) (SkFloat::Cmp(a, b) < 0)
77 #define SkFPLE(a, b) (SkFloat::Cmp(a, b) <= 0)
78 #define SkFPGT(a, b) (SkFloat::Cmp(a, b) > 0)
79 #define SkFPGE(a, b) (SkFloat::Cmp(a, b) >= 0)
80
81#endif
82
83#ifdef SK_DEBUG
84 void SkFP_UnitTest();
85#endif
86
87#endif