Missing mathematical functions in Float

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing mathematical functions in Float

Levente Uzonyi-2
Hi,

recently we had to use tanh (hyperbolic tangent) and found that it's not
in the image. So we rolled our own, but I remembered that we have
FloatMathPlugin which has tanh. I tried it and it worked (the primitive):

Float >> #tanh

  | exp2self |
  <primitive: 'primitiveTanH' module: 'FloatMathPlugin'>
  ^((exp2self := (self + self) exp) - 1.0) / (exp2self + 1.0)

Shouldn't we add all the functions of FloatMathPlugin to Float and the
primitives to existing methods?

(Adding the primitive to #cos gave 2.2x speedup.)


Levente

Reply | Threaded
Open this post in threaded view
|

Re: Missing mathematical functions in Float

Andreas.Raab
Levente Uzonyi wrote:

> recently we had to use tanh (hyperbolic tangent) and found that it's not
> in the image. So we rolled our own, but I remembered that we have
> FloatMathPlugin which has tanh. I tried it and it worked (the primitive):
>
> Float >> #tanh
>
>     | exp2self |
>     <primitive: 'primitiveTanH' module: 'FloatMathPlugin'>
>     ^((exp2self := (self + self) exp) - 1.0) / (exp2self + 1.0)
>
> Shouldn't we add all the functions of FloatMathPlugin to Float and the
> primitives to existing methods?

Could do. I'll point out though that these primitives are designed to
produce bit-identical results (based on fdlibm) and not for speed. But
certainly, where it actually improves speed we should probably take
advantage of it.

Cheers,
   - Andreas