1/*
2 * Copyright (C) 2007 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
17package android.util;
18
19/**
20 * Reimplements _Original_FloatMath with the standard libraries.
21 *
22 * Math routines similar to those found in {@link java.lang.Math}. Performs
23 * computations on {@code float} values directly without incurring the overhead
24 * of conversions to and from {@code double}.
25 *
26 * <p>On one platform, {@code FloatMath.sqrt(100)} executes in one third of the
27 * time required by {@code java.lang.Math.sqrt(100)}.</p>
28 */
29public class FloatMath {
30
31    /** Prevents instantiation. */
32    private FloatMath() {}
33
34    /**
35     * Returns the float conversion of the most positive (i.e. closest to
36     * positive infinity) integer value which is less than the argument.
37     *
38     * @param value to be converted
39     * @return the floor of value
40     */
41    public static float floor(float value) {
42        return (float)Math.floor(value);
43    }
44
45    /**
46     * Returns the float conversion of the most negative (i.e. closest to
47     * negative infinity) integer value which is greater than the argument.
48     *
49     * @param value to be converted
50     * @return the ceiling of value
51     */
52    public static float ceil(float value) {
53        return (float)Math.ceil(value);
54    }
55
56    /**
57     * Returns the closest float approximation of the sine of the argument.
58     *
59     * @param angle to compute the cosine of, in radians
60     * @return the sine of angle
61     */
62    public static  float sin(float angle) {
63        return (float)Math.sin(angle);
64    }
65
66    /**
67     * Returns the closest float approximation of the cosine of the argument.
68     *
69     * @param angle to compute the cosine of, in radians
70     * @return the cosine of angle
71     */
72    public static float cos(float angle) {
73        return (float)Math.cos(angle);
74    }
75
76    /**
77     * Returns the closest float approximation of the square root of the
78     * argument.
79     *
80     * @param value to compute sqrt of
81     * @return the square root of value
82     */
83    public static float sqrt(float value) {
84        return (float)Math.sqrt(value);
85    }
86}
87