| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* eclog1.d - trascendental functions: log(x) |
| 6 |
* |
| 7 |
* Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya |
| 8 |
* Copyright (c) 1990 Giuseppe Attardi |
| 9 |
* Copyright (c) 2001 Juan Jose Garcia Ripoll |
| 10 |
* |
| 11 |
* See file 'LICENSE' for the copyright details. |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
|
| 16 |
#define ECL_INCLUDE_MATH_H |
| 17 |
#include <ecl/ecl.h> |
| 18 |
#include <ecl/internal.h> |
| 19 |
#include <complex.h> |
| 20 |
#include <float.h> |
| 21 |
#include <ecl/impl/math_dispatch.h> |
| 22 |
|
| 23 |
#pragma STDC FENV_ACCESS ON |
| 24 |
|
| 25 |
#ifndef ECL_COMPLEX_FLOAT |
| 26 |
static cl_object |
| 27 |
ecl_log1_complex_inner(cl_object r, cl_object i) |
| 28 |
{ |
| 29 |
cl_object a = ecl_abs(r); |
| 30 |
cl_object p = ecl_abs(i); |
| 31 |
int rel = ecl_number_compare(a, p); |
| 32 |
if (rel > 0) { |
| 33 |
cl_object aux = p; |
| 34 |
p = a; a = aux; |
| 35 |
} else if (rel == 0) { |
| 36 |
/* if a == p, |
| 37 |
* log(sqrt(a^2+p^2)) = log(2a^2)/2 |
| 38 |
*/ |
| 39 |
a = ecl_times(a, a); |
| 40 |
a = ecl_divide(ecl_log1(ecl_plus(a, a)), ecl_make_fixnum(2)); |
| 41 |
goto OUTPUT; |
| 42 |
} |
| 43 |
/* For the real part of the output we use the formula |
| 44 |
* log(sqrt(p^2 + a^2)) = log(sqrt(p^2*(1 + (a/p)^2))) |
| 45 |
* = log(p) + log(1 + (a/p)^2)/2; */ |
| 46 |
a = ecl_divide(a, p); |
| 47 |
a = ecl_plus(ecl_divide(ecl_log1p(ecl_times(a,a)), ecl_make_fixnum(2)), |
| 48 |
ecl_log1(p)); |
| 49 |
OUTPUT: |
| 50 |
p = ecl_atan2(i, r); |
| 51 |
return ecl_make_complex(a, p); |
| 52 |
} |
| 53 |
#endif |
| 54 |
|
| 55 |
static cl_object |
| 56 |
ecl_log1_bignum(cl_object x) |
| 57 |
{ |
| 58 |
cl_fixnum l = ecl_integer_length(x) - 1; |
| 59 |
cl_object r = ecl_make_ratio(x, ecl_ash(ecl_make_fixnum(1), l)); |
| 60 |
float f = ecl_to_float(r); |
| 61 |
if (f < 0) { |
| 62 |
#ifdef ECL_COMPLEX_FLOAT |
| 63 |
return ecl_make_csfloat(clogf(f) + l * logf(2.0)); |
| 64 |
#else |
| 65 |
return ecl_make_complex(ecl_make_single_float(logf(-f) + l * logf(2.0)), ecl_make_single_float(ECL_PI_D)); |
| 66 |
#endif |
| 67 |
} else { |
| 68 |
return ecl_make_single_float(logf(f) + l * logf(2.0)); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
static cl_object |
| 73 |
ecl_log1_simple(cl_object x) |
| 74 |
{ |
| 75 |
float f = ecl_to_float(x); |
| 76 |
if (f < 0) { |
| 77 |
#ifdef ECL_COMPLEX_FLOAT |
| 78 |
return ecl_make_csfloat(clogf(f)); |
| 79 |
#else |
| 80 |
return ecl_make_complex(ecl_make_single_float(logf(-f)), ecl_make_single_float(ECL_PI_D)); |
| 81 |
#endif |
| 82 |
} |
| 83 |
return ecl_make_single_float(logf(f)); |
| 84 |
} |
| 85 |
|
| 86 |
static cl_object |
| 87 |
ecl_log1_ratio(cl_object x) |
| 88 |
{ |
| 89 |
cl_object num = x->ratio.num; |
| 90 |
cl_object den = x->ratio.den; |
| 91 |
cl_index lnum = ecl_integer_length(num); |
| 92 |
cl_index lden = ecl_integer_length(den); |
| 93 |
if ((lnum > lden) ? (lnum - lden >= FLT_MAX_EXP) : (lden - lnum >= -FLT_MIN_EXP)) { |
| 94 |
cl_object numlog = ecl_log1(num); |
| 95 |
cl_object denlog = ecl_log1(den); |
| 96 |
return ecl_minus(numlog, denlog); |
| 97 |
} else { |
| 98 |
return ecl_log1_simple(x); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
static cl_object |
| 103 |
ecl_log1_single_float(cl_object x) |
| 104 |
{ |
| 105 |
float f = ecl_single_float(x); |
| 106 |
if (isnan(f)) return x; |
| 107 |
if (f < 0) { |
| 108 |
#ifdef ECL_COMPLEX_FLOAT |
| 109 |
return ecl_make_csfloat(clogf(f)); |
| 110 |
#else |
| 111 |
return ecl_make_complex(ecl_make_single_float(logf(-f)), ecl_make_single_float(ECL_PI_D)); |
| 112 |
#endif |
| 113 |
} |
| 114 |
return ecl_make_single_float(logf(f)); |
| 115 |
} |
| 116 |
|
| 117 |
static cl_object |
| 118 |
ecl_log1_double_float_inner(cl_object x, double f) |
| 119 |
{ |
| 120 |
if (isnan(f)) return x; |
| 121 |
if (f < 0) { |
| 122 |
#ifdef ECL_COMPLEX_FLOAT |
| 123 |
return ecl_make_cdfloat(clog(f)); |
| 124 |
#else |
| 125 |
return ecl_make_complex(ecl_make_double_float(log(-f)), ecl_make_double_float(ECL_PI_D)); |
| 126 |
#endif |
| 127 |
} |
| 128 |
return ecl_make_double_float(log(f)); |
| 129 |
} |
| 130 |
|
| 131 |
static cl_object |
| 132 |
ecl_log1_double_float(cl_object x) |
| 133 |
{ |
| 134 |
return ecl_log1_double_float_inner(x, ecl_double_float(x)); |
| 135 |
} |
| 136 |
|
| 137 |
static cl_object |
| 138 |
ecl_log1_long_float_inner(cl_object x, long double f) |
| 139 |
{ |
| 140 |
if (isnan(f)) return x; |
| 141 |
if (f < 0) { |
| 142 |
#ifdef ECL_COMPLEX_FLOAT |
| 143 |
return ecl_make_clfloat(clogl(f)); |
| 144 |
#else |
| 145 |
return ecl_make_complex(ecl_make_long_float(logl(-f)), ecl_make_long_float(ECL_PI_L)); |
| 146 |
#endif |
| 147 |
} |
| 148 |
return ecl_make_long_float(logl(f)); |
| 149 |
} |
| 150 |
|
| 151 |
static cl_object |
| 152 |
ecl_log1_long_float(cl_object x) |
| 153 |
{ |
| 154 |
return ecl_log1_long_float_inner(x, ecl_long_float(x)); |
| 155 |
} |
| 156 |
|
| 157 |
static cl_object |
| 158 |
ecl_log1_complex(cl_object x) |
| 159 |
{ |
| 160 |
#ifdef ECL_COMPLEX_FLOAT |
| 161 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 162 |
float _Complex fc = ecl_to_float(x->gencomplex.real) + I * ecl_to_float(x->gencomplex.imag); |
| 163 |
ecl_csfloat(result) = clogf(fc); |
| 164 |
return result; |
| 165 |
#else |
| 166 |
return ecl_log1_complex_inner(x->gencomplex.real, x->gencomplex.imag); |
| 167 |
#endif |
| 168 |
} |
| 169 |
|
| 170 |
#ifdef ECL_COMPLEX_FLOAT |
| 171 |
static cl_object |
| 172 |
ecl_log1_csfloat(cl_object x) |
| 173 |
{ |
| 174 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 175 |
ecl_csfloat(result) = clogf(ecl_csfloat(x)); |
| 176 |
return result; |
| 177 |
} |
| 178 |
|
| 179 |
static cl_object |
| 180 |
ecl_log1_cdfloat(cl_object x) |
| 181 |
{ |
| 182 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 183 |
ecl_cdfloat(result) = clog(ecl_cdfloat(x)); |
| 184 |
return result; |
| 185 |
} |
| 186 |
|
| 187 |
static cl_object |
| 188 |
ecl_log1_clfloat(cl_object x) |
| 189 |
{ |
| 190 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 191 |
ecl_clfloat(result) = clogl(ecl_clfloat(x)); |
| 192 |
return result; |
| 193 |
} |
| 194 |
#endif |
| 195 |
|
| 196 |
MATH_DEF_DISPATCH1(log1, @[log], @[number], |
| 197 |
ecl_log1_simple, ecl_log1_bignum, ecl_log1_ratio, |
| 198 |
ecl_log1_single_float, ecl_log1_double_float, ecl_log1_long_float, |
| 199 |
ecl_log1_complex, |
| 200 |
ecl_log1_csfloat, ecl_log1_cdfloat, ecl_log1_clfloat); |
| 201 |
|
| 202 |
static cl_object ecl_log1_double_precision(cl_object x); |
| 203 |
|
| 204 |
static cl_object |
| 205 |
ecl_log1_bignum_double_precision(cl_object x) |
| 206 |
{ |
| 207 |
cl_fixnum l = ecl_integer_length(x) - 1; |
| 208 |
cl_object r = ecl_make_ratio(x, ecl_ash(ecl_make_fixnum(1), l)); |
| 209 |
double f = ecl_to_double(r); |
| 210 |
if (f < 0) { |
| 211 |
#ifdef ECL_COMPLEX_FLOAT |
| 212 |
return ecl_make_cdfloat(clog(f) + l * log(2.0)); |
| 213 |
#else |
| 214 |
return ecl_make_complex(ecl_make_double_float(log(-f) + l * log(2.0)), ecl_make_double_float(ECL_PI_D)); |
| 215 |
#endif |
| 216 |
} else { |
| 217 |
return ecl_make_double_float(log(f) + l * log(2.0)); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
static cl_object |
| 222 |
ecl_log1_simple_double_precision(cl_object x) |
| 223 |
{ |
| 224 |
double f = ecl_to_double(x); |
| 225 |
if (f < 0) { |
| 226 |
#ifdef ECL_COMPLEX_FLOAT |
| 227 |
return ecl_make_cdfloat(clog(f)); |
| 228 |
#else |
| 229 |
return ecl_make_complex(ecl_make_double_float(log(-f)), ecl_make_double_float(ECL_PI_D)); |
| 230 |
#endif |
| 231 |
} |
| 232 |
return ecl_make_double_float(log(f)); |
| 233 |
} |
| 234 |
|
| 235 |
static cl_object |
| 236 |
ecl_log1_ratio_double_precision(cl_object x) |
| 237 |
{ |
| 238 |
cl_object num = x->ratio.num; |
| 239 |
cl_object den = x->ratio.den; |
| 240 |
cl_index lnum = ecl_integer_length(num); |
| 241 |
cl_index lden = ecl_integer_length(den); |
| 242 |
if ((lnum > lden) ? (lnum - lden >= DBL_MAX_EXP) : (lden - lnum >= -DBL_MIN_EXP)) { |
| 243 |
cl_object numlog = ecl_log1_double_precision(num); |
| 244 |
cl_object denlog = ecl_log1_double_precision(den); |
| 245 |
return ecl_minus(numlog, denlog); |
| 246 |
} else { |
| 247 |
return ecl_log1_simple_double_precision(x); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
static cl_object |
| 252 |
ecl_log1_single_float_double_precision(cl_object x) |
| 253 |
{ |
| 254 |
return ecl_log1_double_float_inner(x, ecl_single_float(x)); |
| 255 |
} |
| 256 |
|
| 257 |
static cl_object |
| 258 |
ecl_log1_complex_double_precision(cl_object x) |
| 259 |
{ |
| 260 |
#ifdef ECL_COMPLEX_FLOAT |
| 261 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 262 |
double _Complex fc = ecl_to_double(x->gencomplex.real) + I * ecl_to_double(x->gencomplex.real); |
| 263 |
ecl_cdfloat(result) = clog(fc); |
| 264 |
return result; |
| 265 |
#else |
| 266 |
return ecl_log1_complex_inner(x->gencomplex.real, x->gencomplex.imag); |
| 267 |
#endif |
| 268 |
} |
| 269 |
|
| 270 |
#ifdef ECL_COMPLEX_FLOAT |
| 271 |
static cl_object |
| 272 |
ecl_log1_csfloat_double_precision(cl_object x) |
| 273 |
{ |
| 274 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 275 |
ecl_cdfloat(result) = clog(ecl_csfloat(x)); |
| 276 |
return result; |
| 277 |
} |
| 278 |
#endif |
| 279 |
|
| 280 |
MATH_DEF_DISPATCH1(log1_double_precision, @[log], @[number], |
| 281 |
ecl_log1_simple_double_precision, ecl_log1_bignum_double_precision, ecl_log1_ratio_double_precision, |
| 282 |
ecl_log1_single_float_double_precision, ecl_log1_double_float, ecl_log1_long_float, |
| 283 |
ecl_log1_complex_double_precision, |
| 284 |
ecl_log1_csfloat_double_precision, ecl_log1_cdfloat, ecl_log1_clfloat); |
| 285 |
|
| 286 |
static cl_object ecl_log1_long_precision(cl_object x); |
| 287 |
|
| 288 |
static cl_object |
| 289 |
ecl_log1_bignum_long_precision(cl_object x) |
| 290 |
{ |
| 291 |
cl_fixnum l = ecl_integer_length(x) - 1; |
| 292 |
cl_object r = ecl_make_ratio(x, ecl_ash(ecl_make_fixnum(1), l)); |
| 293 |
long double f = ecl_to_long_double(r); |
| 294 |
if (f < 0) { |
| 295 |
#ifdef ECL_COMPLEX_FLOAT |
| 296 |
return ecl_make_clfloat(clogl(f) + l * logl(2.0)); |
| 297 |
#else |
| 298 |
return ecl_make_complex(ecl_make_long_float(logl(-f) + l * logl(2.0)), ecl_make_long_float(ECL_PI_L)); |
| 299 |
#endif |
| 300 |
} else { |
| 301 |
return ecl_make_long_float(logl(f) + l * logl(2.0)); |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
static cl_object |
| 306 |
ecl_log1_simple_long_precision(cl_object x) |
| 307 |
{ |
| 308 |
long double f = ecl_to_long_double(x); |
| 309 |
if (f < 0) { |
| 310 |
#ifdef ECL_COMPLEX_FLOAT |
| 311 |
return ecl_make_clfloat(clogl(f)); |
| 312 |
#else |
| 313 |
return ecl_make_complex(ecl_make_long_float(logl(-f)), ecl_make_long_float(ECL_PI_L)); |
| 314 |
#endif |
| 315 |
} |
| 316 |
return ecl_make_long_float(logl(f)); |
| 317 |
} |
| 318 |
|
| 319 |
static cl_object |
| 320 |
ecl_log1_ratio_long_precision(cl_object x) |
| 321 |
{ |
| 322 |
cl_object num = x->ratio.num; |
| 323 |
cl_object den = x->ratio.den; |
| 324 |
cl_index lnum = ecl_integer_length(num); |
| 325 |
cl_index lden = ecl_integer_length(den); |
| 326 |
if ((lnum > lden) ? (lnum - lden >= LDBL_MAX_EXP) : (lden - lnum >= -LDBL_MIN_EXP)) { |
| 327 |
cl_object numlog = ecl_log1_long_precision(num); |
| 328 |
cl_object denlog = ecl_log1_long_precision(den); |
| 329 |
return ecl_minus(numlog, denlog); |
| 330 |
} else { |
| 331 |
return ecl_log1_simple_long_precision(x); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
static cl_object |
| 336 |
ecl_log1_single_float_long_precision(cl_object x) |
| 337 |
{ |
| 338 |
return ecl_log1_long_float_inner(x, ecl_single_float(x)); |
| 339 |
} |
| 340 |
|
| 341 |
static cl_object |
| 342 |
ecl_log1_double_float_long_precision(cl_object x) |
| 343 |
{ |
| 344 |
return ecl_log1_long_float_inner(x, ecl_double_float(x)); |
| 345 |
} |
| 346 |
|
| 347 |
static cl_object |
| 348 |
ecl_log1_complex_long_precision(cl_object x) |
| 349 |
{ |
| 350 |
#ifdef ECL_COMPLEX_FLOAT |
| 351 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 352 |
long double _Complex fc = ecl_to_long_double(x->gencomplex.real) + I * ecl_to_long_double(x->gencomplex.real); |
| 353 |
ecl_clfloat(result) = clogl(fc); |
| 354 |
return result; |
| 355 |
#else |
| 356 |
return ecl_log1_complex_inner(x->gencomplex.real, x->gencomplex.imag); |
| 357 |
#endif |
| 358 |
} |
| 359 |
|
| 360 |
#ifdef ECL_COMPLEX_FLOAT |
| 361 |
static cl_object |
| 362 |
ecl_log1_csfloat_long_precision(cl_object x) |
| 363 |
{ |
| 364 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 365 |
ecl_clfloat(result) = clogl(ecl_csfloat(x)); |
| 366 |
return result; |
| 367 |
} |
| 368 |
|
| 369 |
static cl_object |
| 370 |
ecl_log1_cdfloat_long_precision(cl_object x) |
| 371 |
{ |
| 372 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 373 |
ecl_clfloat(result) = clogl(ecl_cdfloat(x)); |
| 374 |
return result; |
| 375 |
} |
| 376 |
#endif |
| 377 |
|
| 378 |
MATH_DEF_DISPATCH1(log1_long_precision, @[log], @[number], |
| 379 |
ecl_log1_simple_long_precision, ecl_log1_bignum_long_precision, ecl_log1_ratio_long_precision, |
| 380 |
ecl_log1_single_float_long_precision, ecl_log1_double_float_long_precision, ecl_log1_long_float, |
| 381 |
ecl_log1_complex_long_precision, |
| 382 |
ecl_log1_csfloat_long_precision, ecl_log1_cdfloat_long_precision, ecl_log1_clfloat); |
| 383 |
|
| 384 |
cl_object |
| 385 |
ecl_log2(cl_object x, cl_object y) |
| 386 |
{ |
| 387 |
cl_type tx = ecl_t_of(x); |
| 388 |
cl_type ty = ecl_t_of(y); |
| 389 |
/* Prevent loss of precision from intermediate single float results */ |
| 390 |
if (tx == t_longfloat || ty == t_longfloat |
| 391 |
#ifdef ECL_COMPLEX_FLOAT |
| 392 |
|| tx == t_clfloat || ty == t_clfloat |
| 393 |
#endif |
| 394 |
) { |
| 395 |
return ecl_divide(ecl_log1_long_precision(y), ecl_log1_long_precision(x)); |
| 396 |
} |
| 397 |
if (tx == t_doublefloat || ty == t_doublefloat |
| 398 |
#ifdef ECL_COMPLEX_FLOAT |
| 399 |
|| tx == t_cdfloat || ty == t_cdfloat |
| 400 |
#endif |
| 401 |
) { |
| 402 |
return ecl_divide(ecl_log1_double_precision(y), ecl_log1_double_precision(x)); |
| 403 |
} |
| 404 |
return ecl_divide(ecl_log1(y), ecl_log1(x)); |
| 405 |
} |
| 406 |
|
| 407 |
@(defun log (x &optional (y OBJNULL)) |
| 408 |
@ /* INV: type check in ecl_log1() and ecl_log2() */ |
| 409 |
if (y == OBJNULL) { |
| 410 |
@(return ecl_log1(x)); |
| 411 |
} |
| 412 |
/* If base is zero, log returns zero. Using ecl_times takes care of |
| 413 |
the type checking and floating point contagion rules. */ |
| 414 |
if (ecl_unlikely(ecl_zerop(y))) { |
| 415 |
@(return ecl_times(x, y)); |
| 416 |
} |
| 417 |
|
| 418 |
@(return ecl_log2(y, x)) |
| 419 |
@) |
| 420 |
|
| 421 |
cl_object |
| 422 |
si_log1p(cl_object x) |
| 423 |
{ |
| 424 |
@(return ecl_log1p(x)); |
| 425 |
} |
| 426 |
|
| 427 |
static cl_object |
| 428 |
ecl_log1p_simple(cl_object x) |
| 429 |
{ |
| 430 |
float f = ecl_to_float(x); |
| 431 |
if (f < -1) { |
| 432 |
#ifdef ECL_COMPLEX_FLOAT |
| 433 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 434 |
ecl_csfloat(result) = clogf(1.0+f); |
| 435 |
return result; |
| 436 |
#else |
| 437 |
return ecl_log1_complex_inner(ecl_one_plus(x), ecl_make_fixnum(0)); |
| 438 |
#endif |
| 439 |
} |
| 440 |
return ecl_make_single_float(log1pf(ecl_to_float(x))); |
| 441 |
} |
| 442 |
|
| 443 |
static cl_object |
| 444 |
ecl_log1p_single_float(cl_object x) |
| 445 |
{ |
| 446 |
float f = ecl_single_float(x); |
| 447 |
if (isnan(f)) return x; |
| 448 |
if (f < -1) { |
| 449 |
#ifdef ECL_COMPLEX_FLOAT |
| 450 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 451 |
ecl_csfloat(result) = clogf(1+f); |
| 452 |
return result; |
| 453 |
#else |
| 454 |
return ecl_log1_complex_inner(ecl_one_plus(x), ecl_make_fixnum(0)); |
| 455 |
#endif |
| 456 |
} |
| 457 |
return ecl_make_single_float(log1pf(f)); |
| 458 |
} |
| 459 |
|
| 460 |
static cl_object |
| 461 |
ecl_log1p_double_float(cl_object x) |
| 462 |
{ |
| 463 |
double f = ecl_double_float(x); |
| 464 |
if (isnan(f)) return x; |
| 465 |
if (f < -1) { |
| 466 |
#ifdef ECL_COMPLEX_FLOAT |
| 467 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 468 |
ecl_cdfloat(result) = clog(1+f); |
| 469 |
return result; |
| 470 |
#else |
| 471 |
return ecl_log1_complex_inner(ecl_one_plus(x), ecl_make_fixnum(0)); |
| 472 |
#endif |
| 473 |
} |
| 474 |
return ecl_make_double_float(log1p(f)); |
| 475 |
} |
| 476 |
|
| 477 |
static cl_object |
| 478 |
ecl_log1p_long_float(cl_object x) |
| 479 |
{ |
| 480 |
long double f = ecl_long_float(x); |
| 481 |
if (isnan(f)) return x; |
| 482 |
if (f < -1) { |
| 483 |
#ifdef ECL_COMPLEX_FLOAT |
| 484 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 485 |
ecl_clfloat(result) = clogl(1+f); |
| 486 |
return result; |
| 487 |
#else |
| 488 |
return ecl_log1_complex_inner(ecl_one_plus(x), ecl_make_fixnum(0)); |
| 489 |
#endif |
| 490 |
} |
| 491 |
return ecl_make_long_float(log1pl(f)); |
| 492 |
} |
| 493 |
|
| 494 |
static cl_object |
| 495 |
ecl_log1p_complex(cl_object x) |
| 496 |
{ |
| 497 |
#ifdef ECL_COMPLEX_FLOAT |
| 498 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 499 |
float _Complex fc = ecl_to_float(x->gencomplex.real) + I * ecl_to_float(x->gencomplex.real); |
| 500 |
ecl_csfloat(result) = clogf(1+fc); |
| 501 |
return result; |
| 502 |
#else |
| 503 |
return ecl_log1_complex_inner(ecl_one_plus(x), ecl_make_fixnum(0)); |
| 504 |
#endif |
| 505 |
} |
| 506 |
|
| 507 |
#ifdef ECL_COMPLEX_FLOAT |
| 508 |
static cl_object |
| 509 |
ecl_log1p_csfloat(cl_object x) |
| 510 |
{ |
| 511 |
cl_object result = ecl_alloc_object(t_csfloat); |
| 512 |
ecl_csfloat(result) = clogf(1+ecl_csfloat(x)); |
| 513 |
return result; |
| 514 |
} |
| 515 |
|
| 516 |
static cl_object |
| 517 |
ecl_log1p_cdfloat(cl_object x) |
| 518 |
{ |
| 519 |
cl_object result = ecl_alloc_object(t_cdfloat); |
| 520 |
ecl_cdfloat(result) = clog(1+ecl_cdfloat(x)); |
| 521 |
return result; |
| 522 |
} |
| 523 |
|
| 524 |
static cl_object |
| 525 |
ecl_log1p_clfloat(cl_object x) |
| 526 |
{ |
| 527 |
cl_object result = ecl_alloc_object(t_clfloat); |
| 528 |
ecl_clfloat(result) = clogl(1+ecl_clfloat(x)); |
| 529 |
return result; |
| 530 |
} |
| 531 |
#endif |
| 532 |
|
| 533 |
MATH_DEF_DISPATCH1(log1p, @[si::log1p], @[number], |
| 534 |
ecl_log1p_simple, ecl_log1p_simple, ecl_log1p_simple, |
| 535 |
ecl_log1p_single_float, ecl_log1p_double_float, ecl_log1p_long_float, |
| 536 |
ecl_log1p_complex, |
| 537 |
ecl_log1p_csfloat, ecl_log1p_cdfloat, ecl_log1p_clfloat); |