summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/rounding.h
blob: a0efe31dc4de453810adcabba8d85aa4a5e2e34f (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* GTS - Library for the manipulation of triangulated surfaces
 * Copyright (C) 1999 Stéphane Popinet
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_FPU_CONTROL_H
#  include <fpu_control.h>
#  ifdef _FPU_EXTENDED
#   if !defined(__alpha__) || !defined(__GLIBC__)
#    if defined(__arm__)
     static fpu_control_t fpu_round_double = _FPU_DEFAULT;
#    else
     static fpu_control_t fpu_round_double =
       (_FPU_DEFAULT & ~ _FPU_EXTENDED)|_FPU_DOUBLE;
#    endif
     static fpu_control_t fpu_init;
#    define FPU_ROUND_DOUBLE  { _FPU_GETCW(fpu_init);\
                                _FPU_SETCW(fpu_round_double); }
#    define FPU_RESTORE       {_FPU_SETCW(fpu_init);}
#   else /* __alpha__ && __GLIBC__ */
#    define FPU_ROUND_DOUBLE
#    define FPU_RESTORE
#   endif /* __alpha__ && __GLIBC__ */
#  else /* not FPU_EXTENDED */
#    define FPU_ROUND_DOUBLE
#    define FPU_RESTORE
#  endif /* not FPU_EXTENDED */
#else /* not HAVE_FPU_CONTROL_H */
#  ifdef __FreeBSD__
#    include <floatingpoint.h>
#    define FPU_ROUND_DOUBLE  (fpsetprec(FP_PD))
#    define FPU_RESTORE       (fpsetprec(FP_PE))
#  else /* not __FreeBSD__ */
#    ifdef WIN32
#      ifdef _MSC_VER
#        include <float.h>
         static unsigned int fpu_init;
#        define FPU_ROUND_DOUBLE (fpu_init = _controlfp (0, 0),\
                                 _controlfp (_PC_53, MCW_PC))
#        define FPU_RESTORE      (_controlfp (fpu_init, 0xfffff))
#      elif __MINGW32__
#        include <float.h>
         static unsigned int fpu_init;
#        define FPU_ROUND_DOUBLE (fpu_init = _controlfp (0, 0),\
                                  _controlfp (_PC_53, _MCW_PC))
#        define FPU_RESTORE      (_controlfp (fpu_init, 0xfffff))
#      else /* not _MSC_VER or __MINGW32__ */
#        error "You need MSVC or MinGW for the Win32 version"
#      endif /*  not _MSC_VER or __MINGW32__ */
#    else /* not WIN32 */
#      ifdef __CYGWIN__
         typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
         static fpu_control_t fpu_round_double = 0x027f;
         static fpu_control_t fpu_init;
#        define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
#        define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
#        define FPU_ROUND_DOUBLE  { _FPU_GETCW(fpu_init);\
                                    _FPU_SETCW(fpu_round_double); }
#        define FPU_RESTORE       { _FPU_SETCW(fpu_init);}
#      else /* not __CYGWIN__ */
#        ifdef CPP_HAS_WARNING
#          warning "Unknown CPU: assuming default double precision rounding"
#        endif /* CPP_HAS_WARNING */
#        define FPU_ROUND_DOUBLE
#        define FPU_RESTORE
#      endif /* not __CYGWIN__ */
#    endif /* not WIN32 */
#  endif /* not __FreeBSD__ */
#endif /* not HAVE_FPU_CONTROL_H */