Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Überprüfung auf Überlauf beim Rechnen

Empfohlene Antworten

Veröffentlicht

Hi,

ich weiß nicht, wie ich in C auf Überlauf überprüfe. Wenn ich z.B. zwei double Werte multipliziere und das Ergebnis größer als double wäre, wie kann ich dann eben dieses rausfinden? Das Gleiche bräuchte ich auch für alle Grundrechenarten. Gibt es da vielleicht schon fertige Funktionen für?

Wäre für jede Hilfe dankbar.

Hallo!

Unter C gibt eine Datei <limits.h> in der sind alle Type-Grenzen aufgefuehrt. Vielleicht hilft dir das.

smokie

Hallo!

Noch was:) Die Grenzwerte von double stehen bei mir in der <float.h> und nicht <limits.h>. Sorry.

Wenn ich mir das so ueberlege muesste es doch in etwa so gehen?

Da ja nur in Ueberlauf stattfinden kann wenn beide Zahlen das gleiche Vorzeichen haben.....

if (a > 0 && b > 0) {

if (a > DBL_MAX - B)

// overflow

} else if (a < 0 && b < 0) {

if (a < DBL_MIN - B)

// overflow

}

smokie

Danke, werde mir das mal durch den Kopf gehen lassen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.