#include <math.h>
#include <stdio.h>
#include "dsoshadeop.h"

#ifdef __cplusplus
extern "C" {
#endif

EXPORT DS_DispatchTableEntry myabs_shadeops[] = {
     { "float myabs_f(float)", "myabs_init", "myabs_cleanup" },
     { "point myabs_p(point)", "", "" },
     { "vector myabs_p(vector)", "", "" },
     { "", "", "" }
};


EXPORT int myabs_f (void *data, int nargs, void **args)
{
    float *result = (float *) args[0];
    float *x = (float *) args[1];
    *result = fabs (*x);
    return 0;
}


EXPORT int myabs_p (void *data, int nargs, void **args)
{
    float *result = (float *) args[0];
    float *x = (float *) args[1];
    for (int i = 0;  i < 3;  ++i, ++result, ++x)
	*result = fabs (*x);
    return 0;
}


EXPORT void *myabs_init (int, void *)
{
    /* myabs() doesn't really need an initializer, but if it did, here 
     * is where it would go.
     */
    return NULL;
}


EXPORT void myabs_cleanup (void *data)
{
    /* myabs() doesn't really need an cleanup, but if it did, here 
     * is where it would go.
     */
}

#ifdef __cplusplus
}  /* extern "C" */
#endif
