Example #1
0
  //------------------------------------------------------------------------------
  void OprtSign::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)  
  { 
    MUP_ASSERT(a_iArgc==1);

    if (a_pArg[0]->IsScalar())
    {
      *ret = -a_pArg[0]->GetFloat();
    }
    else if (a_pArg[0]->GetType()=='m')
    {
      Value v(a_pArg[0]->GetRows(), 0);
      for (int i=0; i<a_pArg[0]->GetRows(); ++i)
      {
        v.At(i) = -a_pArg[0]->At(i).GetFloat();
      }
      *ret = v;
    }
    else
    {
        ErrorContext err;
        err.Errc = ecINVALID_TYPE;
        err.Type1 = a_pArg[0]->GetType();
        err.Type2 = 's';
        throw ParserError(err);
    }
  }
Example #2
0
  //---------------------------------------------------------------------------
  void RPN::Add(ptr_tok_type tok)
  {
    m_vRPN.push_back(tok);
    if (tok->AsIValue()!=NULL)
    {
      m_nStackPos++;
    }
    else if (tok->AsICallback())
    {
      ICallback *pFun = tok->AsICallback();
      MUP_ASSERT(pFun);
      m_nStackPos -= pFun->GetArgsPresent() - 1;
    }

    MUP_ASSERT(m_nStackPos>=0);
    m_nMaxStackPos = std::max(m_nStackPos, m_nMaxStackPos);
  }
Example #3
0
  //-----------------------------------------------------------------------------------------------
  void OprtSignCmplx::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
  { 
    MUP_ASSERT(a_iArgc==1);

    if (a_pArg[0]->IsScalar() )
    {
      float_type re = a_pArg[0]->GetFloat();
      float_type im = a_pArg[0]->GetImag();

		  // Do not omit the test for zero! Multiplying 0 with -1 
      // will yield -0 on IEEE754 compliant implementations!
      // This would change the result of complex calculations:
      // 
      // i.e. sqrt(-1 + (-0)i) !=  sqrt(-1 + 0i)
      //                   -i  !=  i  
      cmplx_type v((re==0) ? 0 : -re, (im==0) ? 0 : -im);
      *ret = v; 
    }
    else if (a_pArg[0]->GetType()=='m')
    {
      Value v(a_pArg[0]->GetRows(), 0);
      for (int i=0; i<a_pArg[0]->GetRows(); ++i)
      {
        v.At(i) = a_pArg[0]->At(i).GetComplex() * (float_type)-1.0;
      }
      *ret = v;
    }
    else
    {
        ErrorContext err;
        err.Errc = ecINVALID_TYPE;
        err.Type1 = a_pArg[0]->GetType();
        err.Type2 = 's';
        throw ParserError(err);
    }
  }