Christian Ullenboom

1942 Beiträge · Seite 81 von 195

Überlauf in Java 8 erkennen

· Christian Ullenboom

In Java 8 kommen neue Methoden hinzu, die eine Überlauferkennung ermöglichen. Die Methoden gibt es in Math und StrictMath: class java.lang.Math class java.lang.StrictMath static long addExact(long x, long y) static long subtractExact(long x, long y) static long multiplyExact(long x, long y) Alle Methoden werfen eine …

Weiterlesen: Überlauf in Java 8 erkennen →

Math.nextUp(…) und nextDown(…)

· Christian Ullenboom

Was kommt nach und vor 1: Die Ausgabe ist: 1,000000119209289 0,9999999403953552 1,0000001192092896 0,9999999403953552 nextUp(d) ist eine Abkürzung für nextAfter(d, Double.POSITIVE_INFINITY) und nextDown(d) eine Abkürzung für nextAfter(d, Double.NEGATIVE_INFINITY). Ist das zweite Argument von Math.nextAfter(…) größer …

Weiterlesen: Math.nextUp(…) und nextDown(…) →

Division mit Rundung Richtung negativ unendlich, alternativer Restwert

· Christian Ullenboom

Die Ganzzahldivision in Java ist simpel gestrickt. Vereinfacht ausgedrückt: Konvertiere die Ganzzahlen in Fließkommazahlen, führe die Division durch und schneide alles hinter dem Komma ab. So ergeben zum Beispiel 3 / 2 = 1 und 9 / 2 = 4. Bei negativem Ergebnis, durch entweder negativen Dividenden oder Divisor, das …

Weiterlesen: Division mit Rundung Richtung negativ unendlich, alternativer Restwert →

Google Guava Closeables

· Christian Ullenboom

To shorten things and not to repeat ourselves (usually the closing always looks the same) Google Commons offers the utility class com.google.common.io.Closeables. In this class you can find two static helper methods close(Closeable) and closeQuietly(Closeable). Both take an argument of type Closeable—like a …

Weiterlesen: Google Guava Closeables →