File: floating_point_exception.cc

package info (click to toggle)
eckit 1.33.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,216 kB
  • sloc: cpp: 112,634; ansic: 2,826; yacc: 590; lex: 361; python: 289; sh: 162; makefile: 50
file content (41 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * (C) Copyright 1996- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation nor
 * does it submit to any jurisdiction.
 */


#include <iostream>
#include <string>

#include "eckit/maths/FloatingPointExceptions.h"
#include "eckit/runtime/Main.h"


int main(int argc, char** argv) {
    eckit::Main::initialise(argc, argv);

    using FPE = eckit::maths::FloatingPointExceptions;

    if (argc > 1) {
        FPE::enable_floating_point_exceptions(argv[1]);
        FPE::enable_custom_signal_handlers();
        FPE::test(argv[1]);  // should raise a signal
    }
    else {
        FPE::enable_floating_point_exceptions();
        FPE::enable_custom_signal_handlers();
        FPE::test("FE_DIVBYZERO");
    }
    if (argc > 1) {
        std::cout << "Could not trap " << argv[1] << std::endl;
    }
    else {
        std::cout << "Could not trap FE_DIVBYZERO" << std::endl;
    }
    return 1;
}