  uses console
  
  ! FUNCTION GetTickCount     LIB "KERNEL32.DLL" () AS DWORD

'from O2 core float macro-functions
'data  "hypot 17 fmul st0 : fxch : fmul st0 : faddp st1 : fsqrt"
'data  "recip 17 fld1 : fdivrp"

deff rsqrt
fsqrt : fld1 : fdivrp
end deff

deff hypot3
fmul st0 : fxch : fmul st0 : faddp st1 : fxch : fmul st0 : faddp st1  : fsqrt
end deff

float a=9,b=2,c=3,d

d=rsqrt(a)

d=recip(hypot3(a,b,c))

  DWORD gtc, i
  double d
  
  function my_sqrt(float v) as float
    float vhalf = 0.5 * v
    union utype {
      float f
      int i
    }
    dim u as utype
    u.f = v
    u.i = 0x5F325A82 - (u.i >> 1) // initial guess
    return v * u.f * (1.50015 - vhalf * u.f * u.f) // Newton step
  end function

 
  function my_exp(double v) as double
    'assume indexbase 1
    static double k1=1512775.0
    static double k2=1072632447.0
    int q[2]
    q[2] = k1 * v + k2
    return (double) q
  end function
  
  int shift = 1 << 23
  double ishift=1.0/shift

  function my_log(float v) as float
    static double k1 = 0.69314718
    static double k2 = 126.94269504
    float y=(int) v
    'return k1 * (y*ishift - k2)
    #noprec return y * ishift - k2 * k1
  end function


  gtc = GetTickCount()
  float f
  for i = 0 to 10000000
    'd = sqrt(5)
    'd = rsqrt(5)
     f=5
    rsqrtss xmm0,f
    movss  f,xmm0
  next
'd=f


'function csqrt(float v) as float
'return sqrt(v)
'end function

  print "SQRT done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr
  gtc = GetTickCount()
  for i = 0 to 10000000
    d = my_sqrt(5)
    'd=csqrt 5
  next
  print "MYSQRT done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr
  
  gtc = GetTickCount()
  for i = 0 to 10000000
    d = exp(5)
  next
  print "EXP done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr

  gtc = GetTickCount()
  for i = 0 to 10000000
    d = my_exp(5)
  next
  print "MYEXP done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr
  
  gtc = GetTickCount()
  for i = 0 to 10000000
    d = log(5)
  next
  print "LOG done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr
  gtc = GetTickCount()
  for i = 0 to 10000000
    d = my_log(5)
  next
  print "MYLOG done in " (GetTickCount() - gtc) / 1000 " sec ==> " d cr

  print cr "Press any key to continue ..."
  waitkey
  
  ' // DynC Equivalents
  ' float my_sqrt(const float x) { // 8 times faster than MSVCRT, 6 times faster than in O2
    ' const float xhalf = 0.5f * x;
    ' union {
      ' float f;
      ' int i;
    ' } u = {x};
    ' u.i = 0x5F325A82 - (u.i >> 1); // initial guess
    ' return x * u.f * (1.50015f - xhalf * u.f * u.f); // Newton step
  ' }
  
  ' double my_exp(double v) { // 5 times faster than MSVCRT, 3 times faster than in O2
    ' union {
      ' double d;
      ' long long l;
    ' } u;
    ' u.d = v;
    ' u.l = ((long long)(1512775 * v + 1072632447)) << 32;
    ' return u.d;
  ' }
  
  ' float my_log(float x){ // 7 times faster than MSVCRT, 3 times faster than in O2
    ' union { float f; int i; } vx = {x};
    ' float y = vx.i;
    ' y *= 1.0 / (1 << 23);
    ' return 0.69314718f * (y - 126.94269504f);
  ' }