[mercury-users] Math module Trigonometry

Ralph Becket rafe at cs.mu.OZ.AU
Fri Oct 25 15:59:29 AEST 2002


Noel  Pinto, Friday, 25 October 2002:
> Hi,
> 
> I am doing some R & D in the coding for trignometry functions such 
> as sine, cosine and tangent.

I think the ancient Greeks might have beaten you to it.

> 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...

What?

> :- 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.

Oh, please read the manual.
Then read the compilation errors.
Then put two and two together.

Clue #1: variables in Mercury start with a CAPITAL LETTER.  Pretty much
everything else is a symbol (name).

Clue #2: you only want to use DCG notation WHERE YOU'RE DOING IO.

Clue #3: the library modules tell you how many arguments each predicate
takes and what their types are.  Where, pray tell, does the io module
tell us of a predicate called io__write_float that takes *two* float
arguments?

Clue #4: if the compiler tells you about an undefined symbol, what do
you think that means?

Clue #5: there is a limit to the amount of help you can expect to
receive if you persist in failing to read what you are pointed at and
post problems containing bugs that are readily identified by reading the
VERY FIRST PART OF THE MANUAL.

- Ralph
--------------------------------------------------------------------------
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