[mercury-users] Math module Trigonometry

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Fri Oct 25 15:55:25 AEST 2002


* Noel  Pinto <cool4life at rediffmail.com> [2002-10-25 07:37]:
> Hi,
> 
> I am doing some R & D in the coding for trignometry functions such 
> as sine, cosine and tangent.
> 
> Sine    = opposite side of triangle / hypotenuse
> 
> Cosine    = adjacent side of triangle / hypotenuse
> 
> Tangent    = sin / cos
> 
> I am trying to write functions for them and since there are some 
> operations in the module, I am trying to use them by passing 
> values to it and get the output. The code is as below...
> 
> :- module trigo.
> 
> :- interface.
> :- import_module io.
> 
> :- pred main(io__state, io__state).
> :- mode main(di, uo) is det.
> 
> :- implementation.
> :- import_module math, float, exception, string.
> 
> main -->
>         print("Enter the angle : "), flush_output,
>         read_float(angle), nl,
>         print("Enter the hypotenuse : "), flush_output,
>         read_float(hyp), nl,
>         io__write_float(angle, hyp), nl,
> 
>         print(" Sin of "), print(" : "),
>         { sinF(angle, hyp) = f1},
>         io__write_float(f1).
> 
> :- func sinF(float::in, float::in) = float::out is det.
> sinF(angle, hyp) = Float -->
>         { math__sin(angle, hyp) = f1},
>         Float = f1.
> 
>  I am confused as to how sin, cos and tan work in Mercury and how 
> to write function for their calculation.
> These are the errors which I get... Plz do help me rectify them.

Two major errors you are making: 
1. in Mercury, variable names start with a capital letter. So in your
main-predicate you should be talking about "read_float(Angle)", etc... 
2. you declare your function as a two parameter function. There is no
I/O involved, which means there is definitely no need for DCG notation. 
Look-up the documentation of how normal functions should be written in 
Mercury. (hint: ":-" instead of "-->", and no curly brackets inside). 

Good luck, 
Nancy
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list