Home | History | Annotate | Line # | Download | only in m4
      1      1.1  christos # fpieee.m4 serial 2  -*- coding: utf-8 -*-
      2  1.1.1.2  christos dnl Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc.
      3      1.1  christos dnl This file is free software; the Free Software Foundation
      4      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6      1.1  christos 
      7      1.1  christos dnl IEEE 754 standardized three items:
      8      1.1  christos dnl - The formats of single-float and double-float - nowadays commonly
      9      1.1  christos dnl   available as 'float' and 'double' in C and C++.
     10      1.1  christos dnl   No autoconf test needed.
     11      1.1  christos dnl - The overflow and division by zero behaviour: The result are values
     12      1.1  christos dnl   'Inf' and 'NaN', rather than exceptions as it was before.
     13      1.1  christos dnl   This file provides an autoconf macro for ensuring this behaviour of
     14      1.1  christos dnl   floating-point operations.
     15      1.1  christos dnl - A set of conditions (overflow, underflow, inexact, etc.) which can
     16      1.1  christos dnl   be configured to trigger an exception.
     17      1.1  christos dnl   This cannot be done in a portable way: it depends on the compiler,
     18      1.1  christos dnl   libc, kernel, and CPU.  No autoconf macro is provided for this.
     19      1.1  christos 
     20      1.1  christos dnl Ensure non-trapping behaviour of floating-point overflow and
     21      1.1  christos dnl floating-point division by zero.
     22      1.1  christos dnl (For integer overflow, see gcc's -ftrapv option; for integer division by
     23      1.1  christos dnl zero, see the autoconf macro in intdiv0.m4.)
     24      1.1  christos 
     25      1.1  christos AC_DEFUN([gl_FP_IEEE],
     26      1.1  christos [
     27      1.1  christos   AC_REQUIRE([AC_PROG_CC])
     28      1.1  christos   AC_REQUIRE([AC_CANONICAL_HOST])
     29      1.1  christos   # IEEE behaviour is the default on all CPUs except Alpha and SH
     30      1.1  christos   # (according to the test results of Bruno Haible's ieeefp/fenv_default.m4
     31      1.1  christos   # and the GCC 4.1.2 manual).
     32      1.1  christos   case "$host_cpu" in
     33      1.1  christos     alpha*)
     34      1.1  christos       # On Alpha systems, a compiler option provides the behaviour.
     35      1.1  christos       # See the ieee(3) manual page, also available at
     36      1.1  christos       # <https://backdrift.org/man/tru64/man3/ieee.3.html>
     37      1.1  christos       if test -n "$GCC"; then
     38      1.1  christos         # GCC has the option -mieee.
     39      1.1  christos         # For full IEEE compliance (rarely needed), use option -mieee-with-inexact.
     40      1.1  christos         CPPFLAGS="$CPPFLAGS -mieee"
     41      1.1  christos       else
     42      1.1  christos         # Compaq (ex-DEC) C has the option -ieee, equivalent to -ieee_with_no_inexact.
     43      1.1  christos         # For full IEEE compliance (rarely needed), use option -ieee_with_inexact.
     44      1.1  christos         CPPFLAGS="$CPPFLAGS -ieee"
     45      1.1  christos       fi
     46      1.1  christos       ;;
     47      1.1  christos     sh*)
     48      1.1  christos       if test -n "$GCC"; then
     49      1.1  christos         # GCC has the option -mieee.
     50      1.1  christos         CPPFLAGS="$CPPFLAGS -mieee"
     51      1.1  christos       fi
     52      1.1  christos       ;;
     53      1.1  christos   esac
     54      1.1  christos ])
     55