Branch: Tag:

2016-05-17

2016-05-17 14:12:25 by Per Hedbor <ph@opera.com>

Added ** as the exponentiation operator.

3744:    }   }    +  +  +  + PMOD_EXPORT void f_exponent(INT32 args) + { +  double a, b; +  +  if(args != 2 ) +  SIMPLE_WRONG_NUM_ARGS_ERROR("`**",2); +  +  switch( TWO_TYPES(TYPEOF(sp[-2]), TYPEOF(sp[-1])) ) +  { +  case TWO_TYPES(T_FLOAT,T_FLOAT): +  a = sp[-2].u.float_number; +  b = sp[-1].u.float_number; +  goto res_is_powf; +  +  case TWO_TYPES(T_FLOAT,T_INT): +  a = sp[-2].u.float_number; +  b = (double)sp[-1].u.integer; +  goto res_is_powf; +  +  case TWO_TYPES(T_INT,T_FLOAT): +  a = (double)sp[-2].u.integer; +  b = (double)sp[-1].u.float_number; +  +  res_is_powf: +  { +  double r = pow( a, b ); +  if( r != HUGE_VAL ) +  { +  sp-=2; +  push_float( r ); +  return; +  } +  } +  /* When float overflows, switch to bignums. FIXME: mpf? */ +  /* fallthrough */ +  +  default: +  stack_swap(); +  convert_stack_top_to_bignum(); +  stack_swap(); +  /* fallthrough again (le slow path).. */ +  case TWO_TYPES(T_OBJECT,T_INT): +  case TWO_TYPES(T_OBJECT,T_OBJECT): +  if( !call_lfun( LFUN_POW, LFUN_POW ) ) +  Pike_error("Illegal argument 1 to `**.\n"); +  return; +  } +  + } +  +    /*! @decl mixed `*(mixed arg1)    *! @decl mixed `*(object arg1, mixed arg2, mixed ... extras)    *! @decl mixed `*(mixed arg1, object arg2)
5875:    "function(string,int:string)    "function(string,float:string)    */ +  ADD_EFUN2("`**", f_exponent, +  tOr4(tFunc(tInt tInt,tInt), +  tFunc(tFloat tFloat, tFloat), +  tFunc(tInt tFloat, tFloat), +  tFunc(tFloat tInt, tFloat)), +  OPT_TRY_OPTIMIZE,0,0); +     ADD_EFUN2("`*", f_multiply,    tOr9(tIfnot(tFuncV(tNone,tNot(tOr(tObj,tMix)),tMix),    tFuncV(tNone,tOr(tMix,tVoid),tMix)),