/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * log.c
 *
 * Code generation for function 'log'
 *
 */

/* Include files */
#include "log.h"
#include "digital_option_price_cg_data.h"
#include "digital_option_price_cg_types.h"
#include "eml_int_forloop_overflow_check.h"
#include "rt_nonfinite.h"
#include "mwmathutil.h"

/* Variable Definitions */
static emlrtRSInfo fc_emlrtRSI = {
    17,    /* lineNo */
    "log", /* fcnName */
    "/Applications/MATLAB_R2024b.app/toolbox/eml/lib/matlab/elfun/log.m" /* pathName
                                                                          */
};

static emlrtRTEInfo h_emlrtRTEI = {
    14,    /* lineNo */
    9,     /* colNo */
    "log", /* fName */
    "/Applications/MATLAB_R2024b.app/toolbox/eml/lib/matlab/elfun/log.m" /* pName
                                                                          */
};

/* Function Definitions */
void b_log(creal_T *x)
{
  if (x->im == 0.0) {
    if (x->re < 0.0) {
      x->re = muDoubleScalarLog(muDoubleScalarAbs(x->re));
      x->im = 3.1415926535897931;
    } else {
      x->re = muDoubleScalarLog(muDoubleScalarAbs(x->re));
      x->im = 0.0;
    }
  } else if ((muDoubleScalarAbs(x->re) > 8.9884656743115785E+307) ||
             (muDoubleScalarAbs(x->im) > 8.9884656743115785E+307)) {
    real_T d;
    real_T d1;
    d = x->re;
    d1 = x->im;
    x->re = muDoubleScalarLog(muDoubleScalarHypot(d / 2.0, d1 / 2.0)) +
            0.69314718055994529;
    x->im = muDoubleScalarAtan2(d1, d);
  } else {
    real_T d;
    real_T d1;
    d = x->re;
    d1 = x->im;
    x->re = muDoubleScalarLog(muDoubleScalarHypot(d, d1));
    x->im = muDoubleScalarAtan2(d1, d);
  }
}

void c_log(const emlrtStack *sp, emxArray_real_T *x)
{
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack st;
  real_T *x_data;
  int32_T i;
  int32_T k;
  boolean_T p;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  x_data = x->data;
  p = false;
  i = x->size[0];
  for (k = 0; k < i; k++) {
    if (p || (x_data[k] < 0.0)) {
      p = true;
    }
  }
  if (p) {
    emlrtErrorWithMessageIdR2018a(
        sp, &h_emlrtRTEI, "Coder:toolbox:ElFunDomainError",
        "Coder:toolbox:ElFunDomainError", 3, 4, 3, "log");
  }
  st.site = &fc_emlrtRSI;
  b_st.site = &gc_emlrtRSI;
  if (x->size[0] > 2147483646) {
    c_st.site = &hc_emlrtRSI;
    check_forloop_overflow_error(&c_st);
  }
  for (k = 0; k < i; k++) {
    x_data[k] = muDoubleScalarLog(x_data[k]);
  }
}

/* End of code generation (log.c) */
