CO538 Anonymous Questions and Answers Keyword Index |
This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.
To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.
Keyword reference for libraries
2006 |
Submission reference: IN1111
Is inverse tan anywhere in the libraries?
Yes:
REAL32 FUNCTION TAN (VAL REAL32 v) -- tangent (single precision) REAL64 FUNCTION DTAN (VAL REAL64 v) -- tangent (double precision) REAL32 FUNCTION ATAN (VAL REAL32 v) -- anti-tangent (single precision) REAL64 FUNCTION DATAN (VAL REAL64 v) -- anti-tangent (double precision)
To use them, you'll need to import and link the relevant math library:
#USE "dblmath.lib" #USE "snglmath.lib"
By the way, you can quickly find these functions by grepping the Inmos math-library sources, which are in KRoC distributions. There's not much documentation unfortunately. All the trig functions work in radians, of course, not in degrees. For example, ATAN(1) is pi/4 radians (i.e. 45 degrees).
To link in the above libraries, you must extend the occPlug "Libraries:" option – currently you're probably using "course". To do this:
-l course -l occama -l occamutl -l snglmath -l dblmath
#USE "dblmath.lib" #USE "snglmath.lib" #INCLUDE "consts.inc" #USE "course.lib" PROC atan (CHAN BYTE keyboard?, screen!, error!) SEQ REAL32 x, y: SEQ x := 1.0 y := ATAN (x) VAL INT pi.1000 IS INT ROUND (4000.0 * y): SEQ out.string ("pi**1000 = ", 0, screen!) out.int (pi.1000, 0, screen!) out.string ("*c*n", 0, screen!) REAL64 x, y: SEQ x := 1.0 y := DATAN (x) VAL INT pi.1000 IS INT ROUND (4000.0 * y): SEQ out.string ("pi**1000 = ", 0, screen!) out.int (pi.1000, 0, screen!) out.string ("*c*n", 0, screen!) :
which produces:
pi*1000 = 3142 pi*1000 = 3142
which are the correct answers, :).
Keywords: libraries
Submission reference: IN1107
How do I get square root in occam?
Something like this:
REAL64 x: SEQ x := DSQRT (64.0) ... out.real64 (x, 0, 0, scr!)
or, if you're using 32-bit floats:
REAL32 x: SEQ x := SQRT (64.0) ... out.real32 (x, 0, 0, scr!)
The two integers (0 and 0 here) specify the number of integer places and number of decimal places — 0 means "as many as required".
Keywords: coursework , libraries
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |