build/stlport/src/complex_trig.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright (c) 1999
michael@0 3 * Silicon Graphics Computer Systems, Inc.
michael@0 4 *
michael@0 5 * Copyright (c) 1999
michael@0 6 * Boris Fomitchev
michael@0 7 *
michael@0 8 * This material is provided "as is", with absolutely no warranty expressed
michael@0 9 * or implied. Any use is at your own risk.
michael@0 10 *
michael@0 11 * Permission to use or copy this software for any purpose is hereby granted
michael@0 12 * without fee, provided the above notices are retained on all copies.
michael@0 13 * Permission to modify the code and to distribute modified code is granted,
michael@0 14 * provided the above notices are retained, and a notice that the code was
michael@0 15 * modified is included with the above copyright notice.
michael@0 16 *
michael@0 17 */
michael@0 18 #include "stlport_prefix.h"
michael@0 19
michael@0 20
michael@0 21 // Trigonometric and hyperbolic functions for complex<float>,
michael@0 22 // complex<double>, and complex<long double>
michael@0 23 #include <complex>
michael@0 24 #include <cfloat>
michael@0 25 #include <cmath>
michael@0 26
michael@0 27 _STLP_BEGIN_NAMESPACE
michael@0 28
michael@0 29
michael@0 30 //----------------------------------------------------------------------
michael@0 31 // helpers
michael@0 32 #if defined (__sgi)
michael@0 33 static const union { unsigned int i; float f; } float_ulimit = { 0x42b2d4fc };
michael@0 34 static const float float_limit = float_ulimit.f;
michael@0 35 static union {
michael@0 36 struct { unsigned int h; unsigned int l; } w;
michael@0 37 double d;
michael@0 38 } double_ulimit = { 0x408633ce, 0x8fb9f87d };
michael@0 39 static const double double_limit = double_ulimit.d;
michael@0 40 static union {
michael@0 41 struct { unsigned int h[2]; unsigned int l[2]; } w;
michael@0 42 long double ld;
michael@0 43 } ldouble_ulimit = {0x408633ce, 0x8fb9f87e, 0xbd23b659, 0x4e9bd8b1};
michael@0 44 # if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 45 # define ldouble_limit ldouble_ulimit.ld
michael@0 46 # endif
michael@0 47 #else
michael@0 48 # if defined (M_LN2) && defined (FLT_MAX_EXP)
michael@0 49 static const float float_limit = float(M_LN2 * FLT_MAX_EXP);
michael@0 50 static const double double_limit = M_LN2 * DBL_MAX_EXP;
michael@0 51 # else
michael@0 52 static const float float_limit = ::log(FLT_MAX);
michael@0 53 static const double double_limit = ::log(DBL_MAX);
michael@0 54 # endif
michael@0 55 # if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 56 # if defined (M_LN2l)
michael@0 57 # define ldouble_limit (M_LN2l * LDBL_MAX_EXP)
michael@0 58 # else
michael@0 59 # define ldouble_limit ::log(LDBL_MAX)
michael@0 60 # endif
michael@0 61 # endif
michael@0 62 #endif
michael@0 63
michael@0 64
michael@0 65 //----------------------------------------------------------------------
michael@0 66 // sin
michael@0 67 template <class _Tp>
michael@0 68 static complex<_Tp> sinT(const complex<_Tp>& z) {
michael@0 69 return complex<_Tp>(::sin(z._M_re) * ::cosh(z._M_im),
michael@0 70 ::cos(z._M_re) * ::sinh(z._M_im));
michael@0 71 }
michael@0 72
michael@0 73 _STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>& z)
michael@0 74 { return sinT(z); }
michael@0 75
michael@0 76 _STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>& z)
michael@0 77 { return sinT(z); }
michael@0 78
michael@0 79 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 80 _STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>& z)
michael@0 81 { return sinT(z); }
michael@0 82 #endif
michael@0 83
michael@0 84 //----------------------------------------------------------------------
michael@0 85 // cos
michael@0 86 template <class _Tp>
michael@0 87 static complex<_Tp> cosT(const complex<_Tp>& z) {
michael@0 88 return complex<_Tp>(::cos(z._M_re) * ::cosh(z._M_im),
michael@0 89 -::sin(z._M_re) * ::sinh(z._M_im));
michael@0 90 }
michael@0 91
michael@0 92 _STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>& z)
michael@0 93 { return cosT(z); }
michael@0 94
michael@0 95 _STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>& z)
michael@0 96 { return cosT(z); }
michael@0 97
michael@0 98 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 99 _STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>& z)
michael@0 100 { return cosT(z); }
michael@0 101 #endif
michael@0 102
michael@0 103 //----------------------------------------------------------------------
michael@0 104 // tan
michael@0 105 template <class _Tp>
michael@0 106 static complex<_Tp> tanT(const complex<_Tp>& z, const _Tp& Tp_limit) {
michael@0 107 _Tp re2 = 2.f * z._M_re;
michael@0 108 _Tp im2 = 2.f * z._M_im;
michael@0 109
michael@0 110 if (::abs(im2) > Tp_limit)
michael@0 111 return complex<_Tp>(0.f, (im2 > 0 ? 1.f : -1.f));
michael@0 112 else {
michael@0 113 _Tp den = ::cos(re2) + ::cosh(im2);
michael@0 114 return complex<_Tp>(::sin(re2) / den, ::sinh(im2) / den);
michael@0 115 }
michael@0 116 }
michael@0 117
michael@0 118 _STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>& z)
michael@0 119 { return tanT(z, float_limit); }
michael@0 120
michael@0 121 _STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>& z)
michael@0 122 { return tanT(z, double_limit); }
michael@0 123
michael@0 124 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 125 _STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>& z)
michael@0 126 { return tanT(z, ldouble_limit); }
michael@0 127 #endif
michael@0 128
michael@0 129 //----------------------------------------------------------------------
michael@0 130 // sinh
michael@0 131 template <class _Tp>
michael@0 132 static complex<_Tp> sinhT(const complex<_Tp>& z) {
michael@0 133 return complex<_Tp>(::sinh(z._M_re) * ::cos(z._M_im),
michael@0 134 ::cosh(z._M_re) * ::sin(z._M_im));
michael@0 135 }
michael@0 136
michael@0 137 _STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>& z)
michael@0 138 { return sinhT(z); }
michael@0 139
michael@0 140 _STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>& z)
michael@0 141 { return sinhT(z); }
michael@0 142
michael@0 143 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 144 _STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>& z)
michael@0 145 { return sinhT(z); }
michael@0 146 #endif
michael@0 147
michael@0 148 //----------------------------------------------------------------------
michael@0 149 // cosh
michael@0 150 template <class _Tp>
michael@0 151 static complex<_Tp> coshT(const complex<_Tp>& z) {
michael@0 152 return complex<_Tp>(::cosh(z._M_re) * ::cos(z._M_im),
michael@0 153 ::sinh(z._M_re) * ::sin(z._M_im));
michael@0 154 }
michael@0 155
michael@0 156 _STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>& z)
michael@0 157 { return coshT(z); }
michael@0 158
michael@0 159 _STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>& z)
michael@0 160 { return coshT(z); }
michael@0 161
michael@0 162 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 163 _STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>& z)
michael@0 164 { return coshT(z); }
michael@0 165 #endif
michael@0 166
michael@0 167 //----------------------------------------------------------------------
michael@0 168 // tanh
michael@0 169 template <class _Tp>
michael@0 170 static complex<_Tp> tanhT(const complex<_Tp>& z, const _Tp& Tp_limit) {
michael@0 171 _Tp re2 = 2.f * z._M_re;
michael@0 172 _Tp im2 = 2.f * z._M_im;
michael@0 173 if (::abs(re2) > Tp_limit)
michael@0 174 return complex<_Tp>((re2 > 0 ? 1.f : -1.f), 0.f);
michael@0 175 else {
michael@0 176 _Tp den = ::cosh(re2) + ::cos(im2);
michael@0 177 return complex<_Tp>(::sinh(re2) / den, ::sin(im2) / den);
michael@0 178 }
michael@0 179 }
michael@0 180
michael@0 181 _STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>& z)
michael@0 182 { return tanhT(z, float_limit); }
michael@0 183
michael@0 184 _STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>& z)
michael@0 185 { return tanhT(z, double_limit); }
michael@0 186
michael@0 187 #if !defined (_STLP_NO_LONG_DOUBLE)
michael@0 188 _STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>& z)
michael@0 189 { return tanhT(z, ldouble_limit); }
michael@0 190 #endif
michael@0 191
michael@0 192 _STLP_END_NAMESPACE

mercurial