~ubuntu-branches/ubuntu/utopic/r-cran-rcpparmadillo/utopic

« back to all changes in this revision

Viewing changes to inst/include/armadillo_bits/arma_cmath.hpp

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2014-07-03 08:50:31 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20140703085031-b9w69d883j36gx8q
Tags: 0.4.320.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2008-2013 Conrad Sanderson
2
 
// Copyright (C) 2008-2013 NICTA (www.nicta.com.au)
 
1
// Copyright (C) 2008-2014 Conrad Sanderson
 
2
// Copyright (C) 2008-2014 NICTA (www.nicta.com.au)
3
3
// 
4
4
// This Source Code Form is subject to the terms of the Mozilla Public
5
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
47
47
    }
48
48
  #else
49
49
    {
50
 
    const bool x_is_inf = ( (x == x) && ((x - x) != float(0)) );
51
 
    const bool x_is_nan = (x != x);
 
50
    const float y = (std::numeric_limits<float>::max)();
52
51
    
53
 
    return ( (x_is_inf == false) && (x_is_nan == false) );
 
52
    return (x == x) && (x >= -y) && (x <= y);
54
53
    }
55
54
  #endif
56
55
  }
76
75
    }
77
76
  #else
78
77
    {
79
 
    const bool x_is_inf = ( (x == x) && ((x - x) != double(0)) );
80
 
    const bool x_is_nan = (x != x);
 
78
    const double y = (std::numeric_limits<double>::max)();
81
79
    
82
 
    return ( (x_is_inf == false) && (x_is_nan == false) );
 
80
    return (x == x) && (x >= -y) && (x <= y);
83
81
    }
84
82
  #endif
85
83
  }
103
101
 
104
102
 
105
103
 
 
104
// rudimentary wrappers for log1p()
 
105
 
 
106
arma_inline
 
107
float
 
108
arma_log1p(const float x)
 
109
  {
 
110
  #if defined(ARMA_USE_CXX11)
 
111
    {
 
112
    return std::log1p(x);
 
113
    }
 
114
  #else
 
115
    {
 
116
    if((x >= float(0)) && (x < std::numeric_limits<float>::epsilon()))
 
117
      {
 
118
      return x;
 
119
      }
 
120
    else
 
121
    if((x < float(0)) && (-x < std::numeric_limits<float>::epsilon()))
 
122
      {
 
123
      return x;
 
124
      }
 
125
    else
 
126
      {
 
127
      return std::log(float(1) + x);
 
128
      }
 
129
    }
 
130
  #endif
 
131
  }
 
132
 
 
133
 
 
134
 
 
135
arma_inline
 
136
double
 
137
arma_log1p(const double x)
 
138
  {
 
139
  #if defined(ARMA_USE_CXX11)
 
140
    {
 
141
    return std::log1p(x);
 
142
    }
 
143
  #elif defined(ARMA_HAVE_LOG1P)
 
144
    {
 
145
    return log1p(x);
 
146
    }
 
147
  #else
 
148
    {
 
149
    if((x >= double(0)) && (x < std::numeric_limits<double>::epsilon()))
 
150
      {
 
151
      return x;
 
152
      }
 
153
    else
 
154
    if((x < double(0)) && (-x < std::numeric_limits<double>::epsilon()))
 
155
      {
 
156
      return x;
 
157
      }
 
158
    else
 
159
      {
 
160
      return std::log(double(1) + x);
 
161
      }
 
162
    }
 
163
  #endif
 
164
  }
 
165
 
 
166
 
 
167
 
 
168
 
 
169
 
106
170
//
107
171
// wrappers for trigonometric functions
108
172
//