StdReal.dcl 2.93 KB
Newer Older
1 2
system module StdReal

Camil Staps's avatar
Camil Staps committed
3 4 5 6
/**
 * Class instances and basic functions for the Real type.
 */

7
// ****************************************************************************************
8 9
//	Concurrent Clean Standard Library Module Version 3.0
//	Copyright 2019 University of Nijmegen
10 11 12 13
// ****************************************************************************************

import	StdOverloaded

14 15 16
instance +			Real	:: !Real !Real -> Real		:== code { addR }
instance -			Real	:: !Real !Real -> Real		:== code { subR }
instance zero		Real	:: Real						:== code { pushR 0.0 }
17

18 19 20
instance *			Real	:: !Real !Real -> Real		:== code { mulR }
instance /			Real	:: !Real !Real -> Real		:== code { divR }
instance one		Real	:: Real						:== code { pushR 1.0 }
21

22 23
instance ^			Real	:: !Real !Real -> Real		:== code { powR }
instance abs		Real	:: !Real -> Real			:== code { absR }
24
instance sign		Real
25
instance ~			Real	:: !Real -> Real			:== code { negR}
26

27
instance ==			Real	:: !Real !Real -> Bool		:== code { eqR }
28

29
instance <  		Real	:: !Real !Real -> Bool		:== code { ltR }
30

31 32
instance toReal		Int		:: !Int -> Real				:== code { ItoR }
instance toReal		Real	:: !Real -> Real			:== code { no_op }
33 34
instance toReal		{#Char}

35 36 37
instance fromReal	Int		:: !Real -> Int				:== code { RtoI }
instance fromReal	Real	:: !Real -> Real			:== code { no_op }
instance fromReal	{#Char}	:: !Real -> {#Char}			:== code { .d 0 2 r ; jsr RtoAC ; .o 1 0 }
38 39 40

//	Logarithmical Functions:

41 42 43 44 45 46 47 48
instance ln			Real	:: !Real -> Real			:== code { lnR }
							//	Logarithm base e
instance log10		Real	:: !Real -> Real			:== code { log10R }
							//	Logarithm base 10
instance exp		Real	:: !Real -> Real			:== code { expR }
							//	e to the power	
instance sqrt		Real	:: !Real -> Real			:== code { sqrtR }
							//	Square root
49 50 51

//	Trigonometrical Functions:

52 53 54 55 56 57 58 59 60 61 62 63
instance sin		Real	:: !Real -> Real			:== code { sinR }
							//	Sinus
instance cos		Real	:: !Real -> Real			:== code { cosR }
							//	Cosinus
instance tan		Real	:: !Real -> Real			:== code { tanR }
							//	Tangens
instance asin		Real	:: !Real -> Real			:== code { asinR }
							//	Arc Sinus
instance acos		Real	:: !Real -> Real			:== code { acosR }
							//	Arc Cosinus
instance atan		Real	:: !Real -> Real			:== code { atanR }
							//	Arc Tangent
64 65 66 67 68 69 70 71 72
instance sinh		Real	//	Hyperbolic Sine
instance cosh		Real	//	Hyperbolic Cosine
instance tanh		Real	//	Hyperbolic Tangent
instance asinh		Real	//	Arc Hyperbolic Sine
instance acosh		Real	//	Arc Hyperbolic Cosine, partial function, only defined if arg > 1.0
instance atanh		Real	//	Arc Hyperbolic Tangent, partial function, only defined if -1.0 < arg < 1.0

//	Additional conversion:

Camil Staps's avatar
Camil Staps committed
73 74 75 76 77 78
/**
 * Imprecise conversion from Real to Int.
 *
 * @param A Real
 * @result The largest integer smaller than the parameter
 */
79
entier			:: !Real -> Int									:== code { entierR }
80 81 82 83 84 85 86

Infinity :== 1E9999
NaN :== 1E9999+(-1E9999)

isNaN x :== if (x==x) False True
isInfinity x :== if (abs x==1E9999) True False
isFinite x :== if (x-x==0.0) True False