Xah Lee wrote:
In lisp, python, perl, etc, you'll have 10 or so lines. In C or Java,
you'll have 50 or hundreds lines.

C:

#include <stdlib.h>
#include <math.h>

void normal(int dim, float* x, float* a) {
   float sum = 0.0f;
   int i;
   float divisor;
   for (i = 0; i < dim; ++i) sum += x[i] * x[i];
   divisor = sqrt(sum);
   for (i = 0; i < dim; ++i) a[i] = x[i]/divisor;
}

Java:

static float[] normal(final float[] x) {
   float sum = 0.0f;
   for (int i = 0; i < x.length; ++i) sum += x[i] * x[i];
   final float divisor = (float) Math.sqrt(sum);
   float[] a = new float[x.length];
   for (int i = 0; i < x.length; ++i) a[i] = x[i]/divisor;
   return a;
}


--
John W. Kennedy
"Never try to take over the international economy based on a radical feminist agenda if you're not sure your leader isn't a transvestite."
  -- David Misch:  "She-Spies", "While You Were Out"
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to