日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

java floatmath_【Android】解决FloatMath类中方法在API 23以后不存在问题

發(fā)布時間:2025/4/5 Android 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java floatmath_【Android】解决FloatMath类中方法在API 23以后不存在问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.問題原因分析

在Android SDK更新至23以上時,我們會發(fā)現(xiàn)之前在某些地方因計算需要使用到的FloatMath類中的方法如FloatMath.ceil()與FloatMath.sin()等都報錯并提示不可用了,FloatMath源碼如下:

package android.util;

/**

* Math routines similar to those found in {@link java.lang.Math}.

* 數(shù)學(xué)例程類似于{@link java.lang.Math}.

*

Historically these methods were faster than the equivalent double-based

* {@link java.lang.Math} methods. On versions of Android with a JIT they

* became slower and have since been re-implemented to wrap calls to

* {@link java.lang.Math}. {@link java.lang.Math} should be used in

* preference.

*

*

All methods were removed from the public API in version 23.

* 所有方法都從版本23的公共API中刪除.

* @deprecated Use {@link java.lang.Math} instead.

* 方法過時,應(yīng)使用java.lang.Math代替.

*/

@Deprecated

public class FloatMath {

/** Prevents instantiation. */

private FloatMath() {}

/**

* Returns the float conversion of the most positive (i.e. closest to

* positive infinity) integer value which is less than the argument.

*

* @param value to be converted

* @return the floor of value

* @removed

*/

public static float floor(float value) {

return (float) Math.floor(value);

}

/**

* Returns the float conversion of the most negative (i.e. closest to

* negative infinity) integer value which is greater than the argument.

*

* @param value to be converted

* @return the ceiling of value

* @removed

*/

public static float ceil(float value) {

return (float) Math.ceil(value);

}

/**

* Returns the closest float approximation of the sine of the argument.

*

* @param angle to compute the cosine of, in radians

* @return the sine of angle

* @removed

*/

public static float sin(float angle) {

return (float) Math.sin(angle);

}

/**

* Returns the closest float approximation of the cosine of the argument.

*

* @param angle to compute the cosine of, in radians

* @return the cosine of angle

* @removed

*/

public static float cos(float angle) {

return (float) Math.cos(angle);

}

/**

* Returns the closest float approximation of the square root of the

* argument.

*

* @param value to compute sqrt of

* @return the square root of value

* @removed

*/

public static float sqrt(float value) {

return (float) Math.sqrt(value);

}

/**

* Returns the closest float approximation of the raising "e" to the power

* of the argument.

*

* @param value to compute the exponential of

* @return the exponential of value

* @removed

*/

public static float exp(float value) {

return (float) Math.exp(value);

}

/**

* Returns the closest float approximation of the result of raising {@code

* x} to the power of {@code y}.

*

* @param x the base of the operation.

* @param y the exponent of the operation.

* @return {@code x} to the power of {@code y}.

* @removed

*/

public static float pow(float x, float y) {

return (float) Math.pow(x, y);

}

/**

* Returns {@code sqrt(}{@code x}{@code 2}{@code +}

* {@code y}{@code 2}{@code )}.

*

* @param x a float number

* @param y a float number

* @return the hypotenuse

* @removed

*/

public static float hypot(float x, float y) {

return (float) Math.hypot(x, y);

}

}

通過觀察類說明可知,FloatMath的所有方法都已經(jīng)從版本23的公共API中刪除,官方提示我們可以使用java.lang.Math類來代替使用。

2.解決方法

使用23以下版本的SDK進(jìn)行編譯,即修改gradle.build文件里的compileSdkVersion為23以下版本即可。

使用Math類中的方法進(jìn)行代替。

總結(jié)

以上是生活随笔為你收集整理的java floatmath_【Android】解决FloatMath类中方法在API 23以后不存在问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。