Lösungshinweise zu den Aufgaben aus Elementare Syntax von C++: Fundamentale Datentypen

Aufgrund der Plattformabhängigkeit der fundamentalen Datentypen in C++ ist es für den Programmierer unerlässlich zu wissen, welcher Datentyp wieviel Speicherplatz belegt und insbesondere in welchen Zahlenbereichen die am häufigsten verwendeten Datentypen (wie short, int, float, double) fehlerfrei eingesetzt werden können. Da man sich die Grenzen der Zahlenbereiche vermutlich nicht merken kann, sollte man zumindest wissen, wie man sie leicht feststellen kann. Dazu werden die in Elementare Syntax von C++: Fundamentale Datentypen gestellten Aufgaben gelöst beziehungsweise Lösungshinweise gegeben.

Einordnung des Artikels

Zeichen

Eigenschaften von Zeichen

1. Führen Sie das Programm FundTyp.cpp aus!

Dokumentieren Sie

int min static_cast<int>(numeric_limits<char>::min());
int max = static_cast<int>(numeric_limits<char>::max());
cout << "sizeof (char) = " << sizeof (char) << endl;

2. Was passiert, wenn man im Programm FundTyp.cpp die Schleife über das Maximum

int max = static_cast<int>(numeric_limits<char>::max());

hinaus weiterlaufen lässt?

Lösungshinweise:

1. Achtung:

Die Angaben sind plattformabhängig. Es gibt insgesamt 256 Zeichen:

2. Nachdem das letzte Zeichen ausgegeben wurde (für i = max = 127), beginnt die Ausgabe wieder bei min = -128.

Ganzzahlige Datentypen (echte Zahlen)

Eigenschaften

Aufgabe:

Suchen Sie in der C++-Dokumentation nach

std::numeric_limits

und versuchen Sie ähnlich wie oben im Programm

FundTyp.cpp
#include <limits>
. . .

möglichst viele Eigenschaften der drei ganzzahligen Datentypen short int, int und long int herauszubekommen.

Dokumentieren Sie die Ergebnisse - Sie werden noch öfter darauf zugreifen müssen.

Lösungshinweise:

Achtung: Die Ergebnisse sind plattformabhängig!

1. Der Datentyp short:

short k;                // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
short m = 10;           // alte Initialisierung
short n = {5};          // neue Initialisierung

cout << "k = " << k << endl;        // k = -1
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(short) << endl;       // 2
cout << sizeof k << endl;            // 2
cout << sizeof n << endl;            // 2

/*         2 Byte = 16 Bit =>
 *         2^16 = 2^(4 * 4) = 16^4 = 65 536
 *         2^15 = 32 768
 */

short min = std::numeric_limits<short>::min();
cout << "min = " << min << endl;        // -32 768

min = std::numeric_limits<short>::lowest();
cout << "lowest = " << min << endl;     // -32 768

short max = std::numeric_limits<short>::max();
cout << "max = " << max << endl;        // 32 767

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = -32 768

cout << "isSigned: " << std::numeric_limits<short>::is_signed << endl;        // isSigned: 1
cout << "isBounded: " << std::numeric_limits<short>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<short>::is_modulo << endl;        // isModulo: 0

2. Der Datentyp unsigned short:

unsigned short k;            // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
unsigned short m = 10;       // alte Initialisierung
unsigned short n {5};        // neue Initialisierung

cout << "k = " << k << endl;        // k = 65 535
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(unsigned short) << endl;       // 2
cout << sizeof k << endl;                     // 2
cout << sizeof n << endl;                     // 2

/*        2 Byte = 16 Bit =>
*         2^16 = 2^(4 * 4) = 16^4 = 65 536
*/

unsigned short min = std::numeric_limits<unsigned short>::min();
cout << "min = " << min << endl;        // 0

min = std::numeric_limits<unsigned short>::lowest();
cout << "lowest = " << min << endl;     // 0

unsigned short max = std::numeric_limits<unsigned short>::max();
cout << "max = " << max << endl;        // 65 535

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = 0

cout << "isSigned: " << std::numeric_limits<unsigned short>::is_signed << endl;        // isSigned: 0
cout << "isBounded: " << std::numeric_limits<unsigned short>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<unsigned short>::is_modulo << endl;        // isModulo: 1

3. Der Datentyp int:

int k;            // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
int m = 10;       // alte Initialisierung
int n {5};        // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(int) << endl;        // 4
cout << sizeof k << endl;           // 4
cout << sizeof n << endl;           // 4

/*        4 Byte = 32 Bit =>
*         2^32 = 2^(8 * 4) = 16^8 = 4 294 967 296
*         2^31 = 2 147 483 648
*/

int min = std::numeric_limits<int>::min();
cout << "min = " << min << endl;            // -2 147 483 648

min = std::numeric_limits<int>::lowest();
cout << "lowest = " << min << endl;         // -2 147 483 648

int max = std::numeric_limits<int>::max();
cout << "max = " << max << endl;            // 2 147 483 647

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = -2 147 483 648

cout << "isSigned: " << std::numeric_limits<int>::is_signed << endl;        // isSigned: 1
cout << "isBounded: " << std::numeric_limits<int>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<int>::is_modulo << endl;        // isModulo: 0

4. Der Datentyp unsigned int:

unsigned int k;                 // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
unsigned int m = 10;            // alte Initialisierung
unsigned int n {5};             // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(unsigned int) << endl;       // 4
cout << sizeof k << endl;                   // 4
cout << sizeof n << endl;                   // 4

/*        4 Byte = 32 Bit =>
*         2^32 = 2^(8 * 4) = 16^8 = 4 294 967 296
*/

unsigned int min = std::numeric_limits<unsigned int>::min();
cout << "min = " << min << endl;            // 0

min = std::numeric_limits<unsigned int>::lowest();
cout << "lowest = " << min << endl;         // 0

unsigned int max = std::numeric_limits<unsigned int>::max();
cout << "max = " << max << endl;            // 4 294 967 295

max = max + 1;
cout << "Overflow: max = " << max << endl;          // Overflow: max = 0

cout << "isSigned: " << std::numeric_limits<unsigned int>::is_signed << endl;        // isSigned: 0
cout << "isBounded: " << std::numeric_limits<unsigned int>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<unsigned int>::is_modulo << endl;        // isModulo: 1

5. Der Datentyp long:

long k;              // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
long m = 10;         // alte Initialisierung
long n = {5};        // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(long) << endl;           // 4
cout << sizeof k << endl;               // 4
cout << sizeof n << endl;               // 4

/*        4 Byte = 32 Bit =>
*         2^32 = 2^(8 * 4) = 16^8 = 4 294 967 296
*         2^31 = 2 147 483 648
*/

long min = std::numeric_limits<long>::min();
cout << "min = " << min << endl;        // -2 147 483 648

min = std::numeric_limits<long>::lowest();
cout << "lowest = " << min << endl;     // -2 147 483 648

long max = std::numeric_limits<long>::max();
cout << "max = " << max << endl;        // 2 147 483 647

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = -2 147 483 648

cout << "isSigned: " << std::numeric_limits<long>::is_signed << endl;        // isSigned: 1
cout << "isBounded: " << std::numeric_limits<long>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<long>::is_modulo << endl;        // isModulo: 0

6. Der Datentyp unsigned long int:

unsigned long int k;             // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
unsigned long int m = 10;        // alte Initialisierung
unsigned long int n = {5};       // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(unsigned long int) << endl;       // 4
cout << sizeof k << endl;                        // 4
cout << sizeof n << endl;                        // 4

/*        4 Byte = 32 Bit =>
*         2^32 = 2^(8 * 4) = 16^8 = 4 294 967 296
*/

unsigned long int min = std::numeric_limits<unsigned long int>::min();
cout << "min = " << min << endl;            // 0

min = std::numeric_limits<unsigned long int>::lowest();
cout << "lowest = " << min << endl;         // 0

unsigned long int max = std::numeric_limits<unsigned long int>::max();
cout << "max = " << max << endl;            // 4 294 967 295

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = 0

cout << "isSigned: " << std::numeric_limits<unsigned long int>::is_signed << endl;        // isSigned: 0
cout << "isBounded: " << std::numeric_limits<unsigned long int>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<unsigned long int>::is_modulo << endl;        // isModulo: 1

7. Der Datentyp long long int:

long long int k;            // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
long long int m = 10;       // alte Initialisierung
long long int n = {5};      // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(long long int) << endl;      // 8
cout << sizeof k << endl;                   // 8
cout << sizeof n << endl;                   // 8

/*        8 Byte = 64 Bit =>
*         2^64 = 2^(8 * 8) = 256^8 ~ 18.4 * 10^18
*         2^62 = 9 223 372 036 854 775 808 ~ 9.22 * 10^18
*/

long long int min = std::numeric_limits<long long int>::min();
cout << "min = " << min << endl;        // - 9 223 372 036 854 775 808

min = std::numeric_limits<long long int>::lowest();
cout << "lowest = " << min << endl;     // -  9 223 372 036 854 775 808

long long int max = std::numeric_limits<long long int>::max();
cout << "max = " << max << endl;        //  9 223 372 036 854 775 807

max = max + 1;
cout << "Overflow: max = " << max << endl;      // Overflow: max = - 9 223 372 036 854 775 808

cout << "isSigned: " << std::numeric_limits<long long int>::is_signed << endl;        // isSigned: 1
cout << "isBounded: " << std::numeric_limits<long long int>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<long long int>::is_modulo << endl;        // isModulo: 0

8. Der Datentyp unsigned long long int:

unsigned long long int k;               // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
unsigned long long int m = 10;          // alte Initialisierung
unsigned long long int n = {5};         // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(unsigned long long int) << endl;         // 8
cout << sizeof k << endl;                               // 8
cout << sizeof n << endl;                               // 8

/*        8 Byte = 64 Bit =>
*         2^64 = 2^(8 * 8) = 256^8 = 18 446 744 073 709 551 616 ~ 18.4 * 10^18
*/

unsigned long long int min = std::numeric_limits<unsigned long long int>::min();
cout << "min = " << min << endl;        // 0

min = std::numeric_limits<unsigned long long int>::lowest();
cout << "lowest = " << min << endl;     // 0

unsigned long long int max = std::numeric_limits<unsigned long long int>::max();
cout << "max = " << max << endl;                //  18 446 744 073 709 551 615

max = max + 1;
cout << "Overflow: max = " << max << endl;          // Overflow: max = 0

cout << "isSigned: " << std::numeric_limits<unsigned long long int>::is_signed << endl;        // isSigned: 0
cout << "isBounded: " << std::numeric_limits<unsigned long long int>::is_bounded << endl;      // isBounded: 1
cout << "isModulo: " << std::numeric_limits<unsigned long long int>::is_modulo << endl;        // isModulo: 1

Zusammenfassung:

sizeof(short);                      // 2 B;     Zahlenbereich: - 32 768,..., 32 767
sizeof(unsigned short);             // 2 B;     Zahlenbereich: 0,..., 65 535

sizeof(int);                        // 4 B;     Zahlenbereich: - 2 147 483 648,..., 2 147 483 647
sizeof(unsigned int);               // 4 B;     Zahlenbereich: 0,..., 4 294 967 296

sizeof(long);                       // 4 B;     Zahlenbereich: - 2 147 483 648,..., 2 147 483 647
sizeof(unsigned long int);          // 4 B;     Zahlenbereich: 0,..., 4 294 967 296

sizeof(long long int);              // 8 B;     Zahlenbereich: - 9 223 372 036 854 775 808,...,  9 223 372 036 854 775 807
sizeof(unsigned long long int);     // 8 B;     Zahlenbereich: 0,..., 18 446 744 073 709 551 615

Arithmetische Operationen

Untersuchen Sie das Verhalten bei einer Division durch 0:

Aufgaben:

1. Untersuchen Sie das Verhalten bei einer Division durch 0:

2. Untersuchen Sie die Eigenschaften der Division mit Rest:

Lösungshinweise:

1. Der Compiler zeigt keinen Fehler an. Erst bei der Ausführung des Programmes tritt ein Fehler auf und das Programm wird beendet.

// Division durch 0
int a = 10;
int b = 0;
c = a / b;          // Kein Compilerfehler; bei Ausführung wird das Programm abgebrochen.
c = a / 0;          // Compiler-Warnung (division by zero); bei Ausführung wird das Programm abgebrochen.
cout << c << endl;

2. Division mit Rest:

Untersucht werden die vier möglichen Vorzeichenkombinationen bei der Division a / b beziehungsweise a % b:

int a = 20;
int b = 3;
int c;

c = a / b;      // Division (mit Rest); c = ganzzahliger Anteil; c = 6
c = a % b;      // modulo (Rest); c = 2

// 4 Fälle:

// a > 0, b > 0:        20 : 3 = 6 Rest 2
cout << " a > 0, b > 0: " << endl;
c = a / b;              // Division (mit Rest);
cout << c << endl;      // c = ganzzahliger Anteil; c = 6
c = a % b;              // modulo (Rest);
cout << c << endl;      // c = 2

// a < 0, b > 0:        - 20 : 3 = - 6 Rest - 2
cout << " a < 0, b > 0: " << endl;
a = - a;
c = a / b;              // Division (mit Rest);
cout << c << endl;      // c = ganzzahliger Anteil; c = -6
c = a % b;              // modulo (Rest);
cout << c << endl;      // c = -2

// a < 0, b < 0:        - 20 :  (- 3) = 6 Rest  - 2     
cout << " a < 0, b < 0: " << endl;
b = - b;
c = a / b;              // Division (mit Rest); c = ganzzahliger Anteil;
cout << c << endl;      //  c = ganzzahliger Anteil; c = 6
c = a % b;              // modulo (Rest);
cout << c << endl;      // c = -2

// a > 0, b < 0:        20 : (- 3) = - 6 Rest 2
cout << " a > 0, b < 0: " << endl;
a = - a;
c = a / b;              // Division (mit Rest);
cout << c << endl;      // c = ganzzahliger Anteil; c = -6
c = a % b;              // modulo (Rest);
cout << c << endl;      // c = 2

Gleitkommazahlen

Eigenschaften

Aufgabe:

Suchen Sie in der C++-Dokumentation nach

std::numeric_limits

und versuchen Sie ähnlich wie oben im Programm

FundTyp.cpp
#include <limits>
. . .

möglichst viele Eigenschaften der Gleitkommazahl-Datentypen float und double herauszubekommen.

Dokumentieren Sie die Ergebnisse - Sie werden noch öfter darauf zugreifen müssen.

Lösungshinweise:

1. Der Datentyp float:

float k;              // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
float m = 10;         // alte Initialisierung
float n = {5};        // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(float) << endl;          // 4
cout << sizeof k << endl;               // 4
cout << sizeof n << endl;               // 4

float minimum = std::numeric_limits<float>::min();
cout << "min = " << minimum << endl;        // 1.17549e-038 (betragsmäßig kleinste float-Zahl)

float low = std::numeric_limits<float>::lowest();
cout << "lowest = " << low << endl;         // -3.40282e+038

float maximum = std::numeric_limits<float>::max();
cout << "max = " << maximum << endl;        // 3.40282e+038

maximum = maximum + 1;
cout << "Overflow: max + 1 = " << maximum << endl;       // Overflow: maximum + 1 = 3.40282e+038 (Addition von 1 ist irrelevant)

maximum = maximum * 100;
cout << "Overflow: max * 100 = " << maximum << endl;      // Overflow: maximum * 100 = 1.#INF

float denormMin = std::numeric_limits<float>::denorm_min();
cout << "denorm_min: " << denormMin << endl;        //  denorm_min:  1.4013e-045
		// denorm_min(): returns the smallest positive subnormal value of the given floating-point type

cout << "isSigned: " << std::numeric_limits<float>::is_signed << endl;               // isSigned: 1
cout << "isBounded: " << std::numeric_limits<float>::is_bounded << endl;             // isBounded: 1
cout << "isModulo: " << std::numeric_limits<float>::is_modulo << endl;               // isModulo: 0
cout << "hasInfinity: " << std::numeric_limits<float>::has_infinity << endl;         // hasInfinity: 1
cout << "round_style: " << std::numeric_limits<float>::round_style << endl;          // round_style: 1
cout << "max_exponent10: " << std::numeric_limits<float>::max_exponent10 << endl;    // max_exponent10: 38
// 10^38 ist die größte Zahl der Form 10^n, die in float gespeichert werden kann

// sinnvoll, da hasInfinity == true
float inf = std::numeric_limits<float>::infinity();
cout << "inf = " << inf << endl;        // inf = 1.#INF

if (maximum == inf)     // true
	cout << "Overflow!!" << endl;

float zero  = 0;
float x = 10 / zero;
cout << "Division durch 0: " << x << endl;      // Division durch 0: 1.#INF; bzw. -1.#INF bei -10 / zero

2. Der Datentyp double:

double k;              // Deklaration ohne Initialisierung; Compiler-Warnung (k is used uninitialized...)
double m = 10;         // alte Initialisierung
double n = {5};        // neue Initialisierung

cout << "k = " << k << endl;        // unbestimmt (Zufallszahl)
cout << "m = " << m << endl;        // m = 10
cout << "n = " << n << endl;        // n = 5

cout << sizeof(double) << endl;          // 8
cout << sizeof k << endl;                // 8
cout << sizeof n << endl;                // 8

double minimum = std::numeric_limits<double>::min();
cout << "min = " << minimum << endl;            // 2.22507e-308 (betragsmäßig kleinste double-Zahl)

double low = std::numeric_limits<double>::lowest();
cout << "lowest = " << low << endl;             // -1.79769e+308

double maximum = std::numeric_limits<double>::max();
cout << "max = " << maximum << endl;            // 1.79769e+308

maximum = maximum + 1;
cout << "Overflow: max + 1 = " << maximum << endl;      // Overflow: maximum + 1 = 1.79769e+308 (Addition von 1 ist irrelevant)

maximum = maximum * 100;
cout << "Overflow: max * 100 = " << maximum << endl;    // Overflow: maximum * 100 = 1.#INF

double denormMin = std::numeric_limits<double>::denorm_min();
cout << "denorm_min: " << denormMin << endl;        //  denorm_min:  4.94066e-324
		// denorm_min(): returns the smallest positive subnormal value of the given floating-point type

cout << "isSigned: " << std::numeric_limits<double>::is_signed << endl;               // isSigned: 1
cout << "isBounded: " << std::numeric_limits<double>::is_bounded << endl;             // isBounded: 1
cout << "isModulo: " << std::numeric_limits<double>::is_modulo << endl;               // isModulo: 0
cout << "hasInfinity: " << std::numeric_limits<double>::has_infinity << endl;         // hasInfinity: 1
cout << "round_style: " << std::numeric_limits<double>::round_style << endl;          // round_style: 1
cout << "max_exponent10: " << std::numeric_limits<double>::max_exponent10 << endl;    // max_exponent10: 308
// 10^308 ist die größte Zahl der Form 10^n, die in double gespeichert werden kann

// sinnvoll, da hasInfinity == true
double inf = std::numeric_limits<double>::infinity();
cout << "inf = " << inf << endl;        // inf = 1.#INF

if (maximum == inf)     // true wegen maximum = maximum * 100 (siehe oben)
	cout << "Overflow!!" << endl;

double zero  = 0;
double x = 10 / zero;
cout << "Division durch 0: " << x << endl;      // Division durch 0: 1.#INF; bzw. -1.#INF bei -10 / zero

3. Zusammenfassung:

// Speicherplatz:
    sizeof(float) << endl;           // 4
    sizeof(double) << endl;          // 8

    // Zahlenbereich:
    // float:       -3.40282e+038 bis 3.40282e+038
    // double:      -1.79769e+308 bis 1.79769e+308

Aufgaben:

1. Wo in der Mathematik werden oben genannte Kriterien verwendet?

Nennen Sie einige Beispiele!

Welche praktische Bedeutung haben sie?

2. Warum tritt der Effekt des Genauigkeitsverlust im Beispiel oben nicht auf, wenn man 1/2 - 1/2 berechnet?

Lösungshinweise:

1. Es gibt zahlreiche Probleme aus der Praxis, die so umformuliert werden, dass man auf die folgenden mathematischen Probleme geführt wird:

2. Es gilt: 1/2 = 2-1, somit kann 1/2 als Dualzahl mit genau einer Nachkommastelle geschrieben werden; sowohl in float als auch in double lautet die Darstellung 0.1 und es muss nicht gerundet werden.

Mathematische Funktionen

Aufgabe:

Berechnen Sie für x = 0, x = ± 0.5 und x = ± 1 folgende Funktionen:

1/x, 1/x2, √x, √(1 - x2), sin x, cos x, tan x, arcsin x, arccos x, exp(x), exp(- x2), ln x, log x.

(die letzten beiden Funktionen sind der natürliche Logarithmus und der Logarithmus zur Basis 10).

Bei welchen Funktionen liegen die gegebenen x-Werte nicht im Definitionsbereich? Wie reagiert die Programm-Ausführung darauf?

Lösungshinweise:

#include <cmath>

// Argument:
cout << "x = " << x << endl;
// Funktionen
cout << "1/x = " << 1 / x << endl;
cout << "1 /x^2 = " << 1 / (x * x) << endl;
cout << "sqrt(x) = " << sqrt(x) << endl;
cout << "sqrt(1 - x^2) = " << sqrt(1 - x*x) << endl;
cout << "sin(x) = " << sin(x) << endl;
cout << "cos(x) = " << cos(x) << endl;
cout << "tan(x) = " << tan(x) << endl;
cout << "arcsin(x) = " << asin(x) << endl;
cout << "arccos(x) = " << acos(x) << endl;
cout << "exp(x) = " << exp(x) << endl;
cout << "exp(-x^2) = " << exp(- x * x) << endl;
cout << "ln(x) = " << log(x) << endl;
cout << "log(x) = " << log10(x) << endl;

Ausgabe für x = 0:

x = 0
1/x = 1.#INF
1 /x^2 = 1.#INF
sqrt(x) = 0
sqrt(1 - x^2) = 1
sin(x) = 0
cos(x) = 1
tan(x) = 0
arcsin(x) = 0
arccos(x) = 1.5708
exp(x) = 1
exp(-x^2) = 1
ln(x) = -1.#INF
log(x) = -1.#INF

Ausgabe für x = 0.5:

x = 0.5
1/x = 2
1 /x^2 = 4
sqrt(x) = 0.707107
sqrt(1 - x^2) = 0.866025
sin(x) = 0.479426
cos(x) = 0.877583
tan(x) = 0.546302
arcsin(x) = 0.523599
arccos(x) = 1.0472
exp(x) = 1.64872
exp(-x^2) = 0.778801
ln(x) = -0.693147
log(x) = -0.30103

Ausgabe für x = 1.0:

x = 1
1/x = 1
1 /x^2 = 1
sqrt(x) = 1
sqrt(1 - x^2) = 0
sin(x) = 0.841471
cos(x) = 0.540302
tan(x) = 1.55741
arcsin(x) = 1.5708
arccos(x) = 0
exp(x) = 2.71828
exp(-x^2) = 0.367879
ln(x) = 0
log(x) = 0

Ausgabe für x = - 1.0:

x = -1
1/x = -1
1 /x^2 = 1
sqrt(x) = -1.#INF
sqrt(1 - x^2) = 0
sin(x) = -0.841471
cos(x) = 0.540302
tan(x) = -1.55741
arcsin(x) = -1.5708
arccos(x) = 3.14159
exp(x) = 0.367879
exp(-x^2) = 0.367879
ln(x) = -1.#INF
log(x) = -1.#INF