English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutorial Básico de Java

Controle de fluxo Java

Java Array

Java Orientação a Objetos (I)

Java Orientação a Objetos (II)

Java Orientação a Objetos (III)

Tratamento de Exceções Java

Java Lista (List)

Java Queue (Fila)

Conjunto Java Map

Conjunto Java Set

Java Entrada e Saída (I/O)

Reader do Java/Writer

Outros tópicos do Java

Uso e exemplo do método Java Math IEEEremainder()

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.

Parâmetros do IEEEremainder()

  • x - Dividendo

  • y - Divisor

Retorno do valor IEEEremainder()

  • De acordo com o IEEE 754Padrão de retorno do resto

Example1:Java Math.IEEEremainder()

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
  }
}

A diferença entre Math.IEEEremainder() e o operador %

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

Java Math Mathematical Methods