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

Tutoriel de base Java

Contrôle de flux Java

Java Tableau

Java Programmation Orientée Objet (I)

Java Programmation Orientée Objet (II)

Java Programmation Orientée Objet (III)

Gestion des exceptions Java

Java List

Java Queue (File d'attente)

Java Map Collection

Java Set Collection

Java Entrée/Sortie (I/O)

Reader Java/Writer

Autres sujets Java

Utilisation et exemple de la méthode Math.IEEEremainder() de Java

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.

Paramètres de IEEEremainder()

  • x - Diviseur

  • y - Diviseur

La valeur de retour de IEEEremainder()

  • Selon IEEE 754Le standard retourne le reste

Example1:Java Math.IEEEremainder()

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 différence entre Math.IEEEremainder() et l'opérateur %

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

Java Math mathematical methods