PennMUSH Community

Changeset 1165

Show
Ignore:
Timestamp:
12/19/07 06:33:04 (8 months ago)
Author:
shawnw
Message:

log(N,e) works as might be expected

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/CHANGES.183

    r1163 r1165  
    5656   result. 
    5757 * log(N,2) uses the C log2() function if available. 
     58 * log(N,e) takes the natural logarithm of N, like ln(). 
    5859 * lports() now takes an optional viewer argument, a la lwho(). By 
    5960   Talvo. 
  • 1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp

    r1124 r1165  
    22742274  log(<number>[, <base>]) 
    22752275  
    2276   Returns the logarithm (base 10, or the given base) of <number>. 
     2276  Returns the logarithm (base 10, or the given base) of <number>.  
     2277  <base> can be a floating-point number, or 'e' for the natural 
     2278  logarithm. 
     2279 
     2280See also: ln() 
    22772281& LPARENT() 
    22782282  lparent(<object>) 
  • 1.8.3/branches/devel/src/funmath.c

    r1138 r1165  
    10971097} 
    10981098 
     1099#ifndef HAVE_LOG2 
     1100static double 
     1101log2(double x) 
     1102{ 
     1103  return log(x) / log(2.0); 
     1104} 
     1105#endif 
     1106 
    10991107/* ARGSUSED */ 
    11001108FUNCTION(fun_log) 
    11011109{ 
    11021110  NVAL num, base; 
     1111  bool base_is_e = false; 
     1112 
    11031113  if (!is_number(args[0])) { 
    11041114    safe_str(T(e_nums), buff, bp); 
     
    11191129  if (nargs == 2) { 
    11201130    if (!is_number(args[1])) { 
    1121       safe_str(T(e_nums), buff, bp); 
    1122       return; 
    1123     } 
    1124     base = parse_number(args[1]); 
    1125  
    1126     if (base <= 1) 
     1131      if (args[1][0] == 'e' && args[1][1] == '\0') 
     1132    base_is_e = true; 
     1133      else { 
     1134    safe_str(T(e_nums), buff, bp); 
     1135    return; 
     1136      } 
     1137    } else  
     1138      base = parse_number(args[1]); 
     1139 
     1140    if (base_is_e) 
     1141      safe_number(log(num), buff, bp); 
     1142    else if (base <= 1) 
    11271143      safe_str(T("#-1 BASE OUT OF RANGE"), buff, bp); 
    11281144    else if (base == 10) 
    11291145      safe_number(log10(num), buff, bp); 
    1130 #ifdef HAVE_LOG2 
    11311146    else if (base == 2) 
    11321147      safe_number(log2(num), buff, bp); 
    1133 #endif 
    11341148    else 
    11351149      safe_number(log(num) / log(base), buff, bp); 
     
    11371151    safe_number(log10(num), buff, bp); 
    11381152} 
    1139  
    1140 #ifndef HAVE_LOG2 
    1141 static double 
    1142 log2(double x) 
    1143 { 
    1144   return log(x) / log(2.0); 
    1145 } 
    1146 #endif 
    11471153 
    11481154/* ARGSUSED */