88#pragma once
99
1010#include " types.h"
11-
11+ #include < stdlib.h>
12+ #include < complex.h>
13+ #include < tgmath.h>
14+ #include < float.h>
15+ #include < cmath>
1216/* !
1317 * Some basic math functions with inline (performance)
1418 * for double and quadruple precision.
@@ -17,41 +21,81 @@ namespace ql
1721{
1822 // Logarithms
1923 inline double Log (double const & x) { return std::log (x); }
24+ #if defined(__x86_64__) || defined(__i386__)
2025 inline qdouble Log (qdouble const & x) { return logq (x); }
21- inline complex Log (complex const & x) { return std::log (x); }
2226 inline qcomplex Log (qcomplex const & x) { return clogq (x); }
27+ #endif
28+ #if defined(__aarch64__)
29+ inline qdouble Log (qdouble const & x) { return std::log (x); }
30+ inline qcomplex Log (qcomplex const & x) { return clogl (x); }
31+ #endif
32+ inline complex Log (complex const & x) { return std::log (x); }
2333
2434 // Power
2535 inline double Pow (double const & x, int const & a) { return std::pow (x, a); }
36+ #if defined(__x86_64__) || defined(__i386__)
2637 inline qdouble Pow (qdouble const & x, int const & a) { return powq (x,a); }
27- inline complex Pow (complex const & x, int const & a) { return std::pow (x,a); }
2838 inline qcomplex Pow (qcomplex const & x, int const & a){ return cpowq (x,a); }
39+ #endif
40+ #if defined(__aarch64__)
41+ inline qdouble Pow (qdouble const & x, int const & a) { return std::pow (x,a); }
42+ inline qcomplex Pow (qcomplex const & x, int const & a){ return cpowl (x,a); }
43+ #endif
44+ inline complex Pow (complex const & x, int const & a) { return std::pow (x,a); }
2945
3046 // Root
3147 inline double Sqrt (double const & x) { return std::sqrt (x); }
48+ #if defined(__x86_64__) || defined(__i386__)
3249 inline qdouble Sqrt (qdouble const & x) { return sqrtq (x); }
33- inline complex Sqrt (complex const & x) { return std::sqrt (x); }
3450 inline qcomplex Sqrt (qcomplex const & x){ return csqrtq (x); }
51+ #endif
52+ #if defined(__aarch64__)
53+ inline qdouble Sqrt (qdouble const & x) { return std::sqrt (x); }
54+ inline qcomplex Sqrt (qcomplex const & x){ return csqrtl (x); }
55+ #endif
56+ inline complex Sqrt (complex const & x) { return std::sqrt (x); }
3557
3658 // Absolute value
3759 inline double Abs (double const & x) { return std::abs (x); }
60+ #if defined(__x86_64__) || defined(__i386__)
3861 inline qdouble Abs (qdouble const & x) { return fabsq (x);}
39- inline double Abs (complex const & x) { return std::abs (x);}
4062 inline qdouble Abs (qcomplex const & x) { return cabsq (x); }
63+ #endif
64+ #if defined(__aarch64__)
65+ inline qdouble Abs (qdouble const & x) { return std::abs (x);}
66+ inline qdouble Abs (qcomplex const & x) { return cabsl (x); }
67+ #endif
68+ inline double Abs (complex const & x) { return std::abs (x);}
4169
4270 // Complex tools, imag, real and conj.
4371 inline double Imag (double const & x) { UNUSED (x); return 0 ; }
4472 inline qdouble Imag (qdouble const & x) { UNUSED (x); return qdouble (0 ); }
4573 inline double Imag (complex const & x) { return x.imag (); }
74+ #if defined(__x86_64__) || defined(__i386__)
4675 inline qdouble Imag (qcomplex const & x){ return cimagq (x);}
76+ #endif
77+ #if defined(__aarch64__)
78+ inline qdouble Imag (qcomplex const & x){ return cimagl (x);}
79+ #endif
4780
4881 inline double Real (double const & x) { return x; }
4982 inline qdouble Real (qdouble const & x) { return x; }
5083 inline double Real (complex const & x) { return x.real (); }
84+ #if defined(__x86_64__) || defined(__i386__)
5185 inline qdouble Real (qcomplex const & x) { return crealq (x); }
86+ #endif
87+ #if defined(__aarch64__)
88+ inline qdouble Real (qcomplex const & x) { return creall (x); }
89+ #endif
5290
5391 inline complex Conjg (complex const & x) { return std::conj (x); }
92+ #if defined(__x86_64__) || defined(__i386__)
5493 inline qcomplex Conjg (qcomplex const & x){ return conjq (x); }
94+ #endif
95+ #if defined(__aarch64__)
96+ inline qcomplex Conjg (qcomplex const & x){ return conjl (x); }
97+ #endif
98+
5599
56100 // Comparison and sign operations
57101 inline int Sign (double const & x) { return (double (0 ) < x) - (x < double (0 )); }
0 commit comments