English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
La méthode Math.IEEEremainder() de Java effectue une division de paramètres spécifiés et retourne le reste selon IEEE 754Le standard retourne le reste
La syntaxe de la méthode IEEEremainder() est :
Math.IEEEremainder(double x, double y)
Attention:La méthode IEEEremainder() est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement en utilisant le nom de la classe Math.
x - Diviseur
y - Diviseur
Selon IEEE 754Le standard retourne le reste
class Main { public static void main(String[] args) { //Variable declaration double arg1 = 25.0; double arg2 = 3.0; //dans arg1et arg2Exécuter Math.IEEEremainder() System.out.println(Math.IEEEremainder(arg1, arg2)); // 1.0 } }
La méthode Math.IEEEremainder() et l'opérateur % retournent un reste égal à arg1 - arg2 * n. Cependant, la valeur de n est différente.
IEEEremainder() - n est le plus proche de arg1/arg2)。And if arg1/arg2Returns the value between two integers, then n is an even integer (i.e. the integer part of the result1.5,n=2)
% operator - n is arg1/arg2the integer part (for the result1.5,n=1)。
class Main { public static void main(String[] args) { //Variable declaration double arg1 = 9.0; double arg2 = 5.0; // Using Math.IEEEremainder() method System.out.println(Math.IEEEremainder(arg1, arg2)); // -1.0 // Using % operator System.out.println(arg1 % arg2); // 4.0 } }
In the above example, we can see that the remainder returned by the IEEEremainder() method and the % operator are different. This is because,
Regarding Math.IEEEremainder()
arg1/arg2 => 1.8 //IEEEremainder() n = 2 arg - arg2 * n => 9.0 - 5.0 * 2.0 => -1.0
Regarding the % operator
arg1/arg2 => 1.8 // % operator n = 1 arg1 - arg2 * n => 9.0 - 5.0 * 1.0 => 4.0