Task

Show how to use the following math constants and functions in your language   (if not available, note it):

   e   (base of the natural logarithm)
   



π


{\displaystyle \pi }


   square root
   logarithm   (any base allowed)
   exponential   (ex )
   absolute value   (a.k.a. "magnitude")
   floor   (largest integer less than or equal to this number--not the same as truncate or int)
   ceiling   (smallest integer not less than this number--not the same as round up)
   power   (xy )


Related task

   Trigonometric Functions


% Implemented by Arjun Sunel
-module(math_constants).
-export([main/0]).
main() ->
	io:format("~p~n",	[math:exp(1)]		),		% e
	io:format("~p~n",	[math:pi()]		),		% pi
	io:format("~p~n",	[math:sqrt(16)]		),		% square root
	io:format("~p~n",	[math:log(10)]		),		% natural logarithm			
	io:format("~p~n",	[math:log10(10)]	),		% base 10 logarithm
	io:format("~p~n",	[math:exp(2)]		),		% e raised to the power of x
	io:format("~p~n",	[abs(-2.24)]		),		% absolute value
	io:format("~p~n",	[floor(3.1423)]		),		% floor
	io:format("~p~n",	[ceil(20.125)]		),		% ceiling
	io:format("~p~n",	[math:pow(3,2)]	        ).		% exponentiation 
 
floor(X) when X < 0 ->
	T = trunc(X),
	case X - T == 0 of
		true -> T;
        	false -> T - 1
	end;
 
floor(X) -> 
	trunc(X).
 
 
ceil(X) when X < 0 ->
	trunc(X);
 
ceil(X) ->
	T = trunc(X),
	case X - T == 0 of
		true -> T;
		false -> T + 1
	end.	
 