Thread View: comp.lang.functional
2 messages
2 total messages
Started by bert thompson
Wed, 26 Aug 1992 08:07
transcendental functions in Gofer
Author: bert thompson
Date: Wed, 26 Aug 1992 08:07
Date: Wed, 26 Aug 1992 08:07
19 lines
1003 bytes
1003 bytes
hi! has anyone implemented any functions in Gofer to do any of the following on Floats: sqrt exp log sin atan erf the sqrt is easy, but the limited support for Floats in Gofer means that the others are hard to do adequately. btw, i don't mind if you've use `primitive' to define them in the interpreter itself. even if you don't have code, hints would be good. i don't have problems with the numerical analysis, but the absence of functions to return the exponent and mantissa of a Float is a real problem. (perhaps Mark Jones might consider defining such functions a la Haskell in the next release?) many thanks! bert.
Re: transcendental functions in Gofer
Author: Fergus James HENDERSON
Date: Wed, 26 Aug 1992 13:33
Date: Wed, 26 Aug 1992 13:33
44 lines
1800 bytes
1800 bytes
aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
>has anyone implemented any functions in Gofer to do any of the following
>on Floats:
>
>sqrt exp log sin atan erf
>
>btw, i don't mind if you've use `primitive' to define them in the interpreter
>itself.
Wed Aug 26 23:24:55 EST 1992
I haven't done these ones myself, but it is VERY easy to add new primitives.
Just add lines like
primitive "primitiveExpFloat" exp :: Float -> Float
to the prelude, add functions like
/* one-argument example */
primFun(primExpFloat) { /* Float exp primitive */
eval(primArg(1));
updateRoot(mkFloat(sin(whnfFloat)));
^^^ substitute as appropriate
}
/* two-argument example */
primFun(primAtan2Float) { /* Float atan2 primitive */
Float x;
eval(primArg(2));
x = whnfFloat;
eval(primArg(1));
updateRoot(mkFloat(atan2(x,whnfFloat)());
^^^^^ substitute as appropriate
}
to "builtin.c", add these functions to the table of builtin functions
in builtin.c, and then just run "make".
P.S. If you have any trouble, I'd be happy to give you a hand.
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads