Math.h
math.h ist eine Header-Datei in der Standard C Library der Programmiersprache C. Sie wurde für mathematische Funktionen entwickelt. Die Programmiersprache C …
math.h ist eine Header-Datei in der Standard C Library der Programmiersprache C. Sie wurde für mathematische Funktionen entwickelt. Die Programmiersprache C++ benutzt die Funktionen ebenfalls, um die Kompatibilität von C zu C++ zu gewährleisten, und deklariert sie in der Header-Datei cmath (dort ohne die Dateinamenserweiterung „.h“ verwendet).
Alle Funktionen, die einen Winkel einlesen oder ausgeben, arbeiten mit Radiant. Die meisten Funktionen arbeiten mit Gleitkommazahlen. Mathematische Funktionen, die mit ganzzahligen Werten (Integer) arbeiten, wie abv, labs, div oder ldiv, sind stattdessen in der Header-Datei stdlib.h vertreten.
Funktionen bis C95
In den Normen bis einschließlich C95 waren die folgenden Funktionen deklariert.
| Name | Beschreibung | Mathematische Formulierung |
|---|---|---|
acos |
Arkuskosinus | |
asin |
Arkussinus | |
atan |
Arkustangens | |
atan2 |
„Arkustangens“ mit zwei Argumenten | |
ceil |
Aufrundungsfunktion | |
cos |
Kosinus | |
cosh |
Kosinus hyperbolicus | |
exp |
Exponentialfunktion | |
fabs |
Betragsfunktion | |
floor |
Ganzteilfunktion | |
fmod |
Führt die Modulo-Funktion für Gleitkommazahlen durch | |
frexp |
Teilt eine Gleitkommazahl in Faktor und Potenz mit der Basis 2 auf | |
ldexp |
Multipliziert den ersten Parameter mit 2 um den zweiten Parameter potenziert | |
log |
Natürlicher Logarithmus | |
log10 |
Logarithmus zur Basis 10 | |
modf |
Teilt eine Gleitkommazahl in zwei Zahlen auf, vor und nach dem Komma | |
pow |
Potenziert ersten mit dem zweiten Parameter | |
sin |
Sinus | |
sinh |
Sinus hyperbolicus | |
sqrt |
Quadratwurzel | |
tan |
Tangens | |
tanh |
Tangens hyperbolicus |
C99-Funktionen
Mit der Norm C99 wurde math.h um die folgenden Funktionen erweitert.
| Name | Beschreibung | Mathematische Formulierung |
|---|---|---|
acosh |
Areakosinus hyperbolicus | |
asinh |
Areasinus hyperbolicus | |
atanh |
Areatangens hyperbolicus | |
cbrt |
Kubikwurzel | |
copysign(x,y) |
gibt den Wert von x mit dem Vorzeichen von y zurück | |
erf |
Fehlerfunktion | |
erfc |
Gibt den Komplementärfehler von x zurück | |
exp2(x) |
Potenziert 2 mit dem übergebenen Parameter | |
expm1(x) |
Liefert den Wert von exp()-1 zurück | |
fdim(x,y) |
Positive Differenz | |
fma(x,y,z) |
Multipliziert und Addiert | |
fmax(x,y) |
Maximum | |
fmin(x,y) |
Minimum | |
hypot(x,y) |
Hypotenuse | |
ilogb |
wie logb, gibt allerdings int zurück |
(int)logb(x)
|
lgamma |
Logarithmus der Gammafunktion | |
llrint |
Rundungsfunktion | |
lrint |
Rundungsfunktion | |
llround |
Rundungsfunktion | |
lround |
Rundungsfunktion | |
log1p(x) |
Natürlicher Logarithmus von 1 + x | |
log2 |
Logarithmus zur Basis 2 | |
logb |
Liefert den ganzzahligen Exponenten einer Gleitkommazahl als Gleitkommazahl | |
nan(s) |
Ein NaN erzeugen | |
nearbyint |
Rundet Gleitkommazahlen zum nächsten Integer | |
nextafter(x,y) |
Gibt die nächst darstellbare Zahl nach x (Richtung y) zurück | |
nexttoward(x,y) |
Wie nextafter, außer dass y als long double übergeben wird |
|
remainder(x,y) |
Rest einer Division | |
remquo(x,y,p) |
Genauso wie remainder, speichert jedoch den Quotienten (als int) als Ziel des Zeigers p |
|
rint |
Rundet je nach Rundungsmodus zum nächsten Integer, gibt eine Gleitkommazahl zurück | |
round |
kaufmännische Rundungsfunktion | |
scalbln(x,y) |
x * FLT_RADIXy (y ist long) |
|
scalbn(x,y) |
x * FLT_RADIXy (y ist int) |
|
tgamma |
Gammafunktion | |
trunc |
Beschneidet eine Gleitkommazahl, d. h. rundet „Richtung Null“ |
Beispiel
#include <stdio.h>
#include <math.h>
int main() {
double a = 5, b = 4;
double c = pow(a, b);
printf("%f hoch %f ist %f\n", a, b, c);
}
Weblinks
- Rationale for International Standard – Programming Languages – C. (PDF, 898 kB) Abgerufen am 4. September 2011 (C99).
- Beschreibung auf cplusplus.com (englisch)
- Dokumentation von math.h auf dinkumware.com ( vom 21. Februar 2010 im Internet Archive)
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.