• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SkFloatingPoint_DEFINED
18 #define SkFloatingPoint_DEFINED
19 
20 #include "SkTypes.h"
21 
22 #ifdef SK_CAN_USE_FLOAT
23 
24 #include <math.h>
25 #include <float.h>
26 #include "SkFloatBits.h"
27 
28 // If math.h had powf(float, float), I could remove this wrapper
sk_float_pow(float base,float exp)29 static inline float sk_float_pow(float base, float exp) {
30     return static_cast<float>(pow(static_cast<double>(base),
31                                   static_cast<double>(exp)));
32 }
33 
34 #ifdef SK_BUILD_FOR_WINCE
35     #define sk_float_sqrt(x)        (float)::sqrt(x)
36     #define sk_float_sin(x)         (float)::sin(x)
37     #define sk_float_cos(x)         (float)::cos(x)
38     #define sk_float_tan(x)         (float)::tan(x)
39     #define sk_float_acos(x)        (float)::acos(x)
40     #define sk_float_asin(x)        (float)::asin(x)
41     #define sk_float_atan2(y,x)     (float)::atan2(y,x)
42     #define sk_float_abs(x)         (float)::fabs(x)
43     #define sk_float_mod(x,y)       (float)::fmod(x,y)
44     #define sk_float_exp(x)         (float)::exp(x)
45     #define sk_float_log(x)         (float)::log(x)
46     #define sk_float_floor(x)       (float)::floor(x)
47     #define sk_float_ceil(x)        (float)::ceil(x)
48 #else
49     #define sk_float_sqrt(x)        sqrtf(x)
50     #define sk_float_sin(x)         sinf(x)
51     #define sk_float_cos(x)         cosf(x)
52     #define sk_float_tan(x)         tanf(x)
53     #define sk_float_floor(x)       floorf(x)
54     #define sk_float_ceil(x)        ceilf(x)
55 #ifdef SK_BUILD_FOR_MAC
56     #define sk_float_acos(x)        static_cast<float>(acos(x))
57     #define sk_float_asin(x)        static_cast<float>(asin(x))
58 #else
59     #define sk_float_acos(x)        acosf(x)
60     #define sk_float_asin(x)        asinf(x)
61 #endif
62     #define sk_float_atan2(y,x) atan2f(y,x)
63     #define sk_float_abs(x)         fabsf(x)
64     #define sk_float_mod(x,y)       fmodf(x,y)
65     #define sk_float_exp(x)         expf(x)
66     #define sk_float_log(x)         logf(x)
67     #define sk_float_isNaN(x)       _isnan(x)
68 #endif
69 
70 #ifdef SK_USE_FLOATBITS
71     #define sk_float_floor2int(x)   SkFloatToIntFloor(x)
72     #define sk_float_round2int(x)   SkFloatToIntRound(x)
73     #define sk_float_ceil2int(x)    SkFloatToIntCeil(x)
74 #else
75     #define sk_float_floor2int(x)   (int)sk_float_floor(x)
76     #define sk_float_round2int(x)   (int)sk_float_floor((x) + 0.5f)
77     #define sk_float_ceil2int(x)    (int)sk_float_ceil(x)
78 #endif
79 
80 #endif
81 #endif
82