Home | History | Annotate | Download | only in util
      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 
     17 package android.util;
     18 
     19 /**
     20  * Math routines similar to those found in {@link java.lang.Math}. On
     21  * versions of Android with a JIT, these are significantly slower than
     22  * the equivalent {@code Math} functions, which should be used in preference
     23  * to these.
     24  */
     25 public class FloatMath {
     26 
     27     /** Prevents instantiation. */
     28     private FloatMath() {}
     29 
     30     /**
     31      * Returns the float conversion of the most positive (i.e. closest to
     32      * positive infinity) integer value which is less than the argument.
     33      *
     34      * @param value to be converted
     35      * @return the floor of value
     36      */
     37     public static native float floor(float value);
     38 
     39     /**
     40      * Returns the float conversion of the most negative (i.e. closest to
     41      * negative infinity) integer value which is greater than the argument.
     42      *
     43      * @param value to be converted
     44      * @return the ceiling of value
     45      */
     46     public static native float ceil(float value);
     47 
     48     /**
     49      * Returns the closest float approximation of the sine of the argument.
     50      *
     51      * @param angle to compute the cosine of, in radians
     52      * @return the sine of angle
     53      */
     54     public static native float sin(float angle);
     55 
     56     /**
     57      * Returns the closest float approximation of the cosine of the argument.
     58      *
     59      * @param angle to compute the cosine of, in radians
     60      * @return the cosine of angle
     61      */
     62     public static native float cos(float angle);
     63 
     64     /**
     65      * Returns the closest float approximation of the square root of the
     66      * argument.
     67      *
     68      * @param value to compute sqrt of
     69      * @return the square root of value
     70      */
     71     public static native float sqrt(float value);
     72 
     73     /**
     74      * Returns the closest float approximation of the raising "e" to the power
     75      * of the argument.
     76      *
     77      * @param value to compute the exponential of
     78      * @return the exponential of value
     79      */
     80     public static native float exp(float value);
     81 
     82     /**
     83      * Returns the closest float approximation of the result of raising {@code
     84      * x} to the power of {@code y}.
     85      *
     86      * @param x the base of the operation.
     87      * @param y the exponent of the operation.
     88      * @return {@code x} to the power of {@code y}.
     89      */
     90     public static native float pow(float x, float y);
     91 
     92     /**
     93      * Returns {@code sqrt(}<i>{@code x}</i><sup>{@code 2}</sup>{@code +} <i>
     94      * {@code y}</i><sup>{@code 2}</sup>{@code )}.
     95      *
     96      * @param x a float number
     97      * @param y a float number
     98      * @return the hypotenuse
     99      */
    100     public static native float hypot(float x, float y);
    101 }
    102