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 * Math routines similar to those found in {@link java.lang.Math}. Performs
21 * computations on {@code float} values directly without incurring the overhead
22 * of conversions to and from {@code double}.
23 *
24 * <p>On one platform, {@code FloatMath.sqrt(100)} executes in one third of the
25 * time required by {@code java.lang.Math.sqrt(100)}.</p>
26 */
27public class FloatMath {
28
29    /** Prevents instantiation. */
30    private FloatMath() {}
31
32    /**
33     * Returns the float conversion of the most positive (i.e. closest to
34     * positive infinity) integer value which is less than the argument.
35     *
36     * @param value to be converted
37     * @return the floor of value
38     */
39    public static native float floor(float value);
40
41    /**
42     * Returns the float conversion of the most negative (i.e. closest to
43     * negative infinity) integer value which is greater than the argument.
44     *
45     * @param value to be converted
46     * @return the ceiling of value
47     */
48    public static native float ceil(float value);
49
50    /**
51     * Returns the closest float approximation of the sine of the argument.
52     *
53     * @param angle to compute the cosine of, in radians
54     * @return the sine of angle
55     */
56    public static native float sin(float angle);
57
58    /**
59     * Returns the closest float approximation of the cosine of the argument.
60     *
61     * @param angle to compute the cosine of, in radians
62     * @return the cosine of angle
63     */
64    public static native float cos(float angle);
65
66    /**
67     * Returns the closest float approximation of the square root of the
68     * argument.
69     *
70     * @param value to compute sqrt of
71     * @return the square root of value
72     */
73    public static native float sqrt(float value);
74
75    /**
76     * Returns the closest float approximation of the raising "e" to the power
77     * of the argument.
78     *
79     * @param value to compute the exponential of
80     * @return the exponential of value
81     */
82    public static native float exp(float value);
83
84    /**
85     * Returns the closest float approximation of the result of raising {@code
86     * x} to the power of {@code y}.
87     *
88     * @param x the base of the operation.
89     * @param y the exponent of the operation.
90     * @return {@code x} to the power of {@code y}.
91     */
92    public static native float pow(float x, float y);
93
94    /**
95     * Returns {@code sqrt(}<i>{@code x}</i><sup>{@code 2}</sup>{@code +} <i>
96     * {@code y}</i><sup>{@code 2}</sup>{@code )}.
97     *
98     * @param x a float number
99     * @param y a float number
100     * @return the hypotenuse
101     */
102    public static native float hypot(float x, float y);
103}
104