English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
O método Java Math IEEEremainder() realiza a operação de divisão para os parâmetros especificados e, de acordo com o IEEE 754Padrão de retorno do resto.
A sintaxe do método IEEEremainder() é:
Math.IEEEremainder(double x, double y)
Atenção:O método IEEEremainder() é um método estático. Portanto, podemos usar o nome da classe Math para chamar diretamente o método.
x - Dividendo
y - Divisor
De acordo com o IEEE 754Padrão de retorno do resto
class Main { public static void main(String[] args) { //Variable Declaration double arg1 = 25.0; double arg2 = 3.0; //em arg1e arg2Executar Math.IEEEremainder() System.out.println(Math.IEEEremainder(arg1, arg2)); // 1.0 } }
O método Math.IEEEremainder() e o operador % retornam o resto igual a arg1 - arg2 * n. No entanto, o valor de n é diferente.
IEEEremainder() - n é o mais próximo de arg1/arg2of the result. 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