How to use trigonometric functions with Data.Scientific?

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

How to use trigonometric functions with Data.Scientific?

Martin Vlk
Hi, I am writing a program to do some astronomical calculation, and I am
using the Data.Scientific library to represent my floating point
numbers. Would anyone know how to use trigonometric functions with the
Scientific type?

I see:
a :: Scientific
a = scientific 500036 (-5)

sin :: Floating a => a -> a

-- this won't work
wrongType = sin a

Any ideas?

Many Thanks
Martin
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use trigonometric functions with Data.Scientific?

David McBride
You should be able to use sin (toRealFloat a).  But I imagine that could introduce some error into your calculations.  You will have to make sure you put enough type signatures to infer Double.

On Tue, Jun 2, 2015 at 6:51 AM, Martin Vlk <[hidden email]> wrote:
Hi, I am writing a program to do some astronomical calculation, and I am
using the Data.Scientific library to represent my floating point
numbers. Would anyone know how to use trigonometric functions with the
Scientific type?

I see:
a :: Scientific
a = scientific 500036 (-5)

sin :: Floating a => a -> a

-- this won't work
wrongType = sin a

Any ideas?

Many Thanks
Martin
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to use trigonometric functions with Data.Scientific?

Martin Vlk
David McBride:
> You should be able to use sin (toRealFloat a).  But I imagine that could
> introduce some error into your calculations.  You will have to make sure
> you put enough type signatures to infer Double.
>

Hi David, many thanks for your reply.
In the end I found the problem was not in precision, but rather a much
more mundane mistake - I failed to notice the trigonometric functions
expect input value in radians, not degrees. Doh! :-)

Now my calculation works as expected.

Thanks again
Martin
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners