%mathpiper,def="Ceil"

5 # Ceil(Infinity) <-- Infinity;
5 # Ceil(-Infinity) <-- -Infinity;
5 # Ceil(Undefined) <-- Undefined;

10 # Ceil(x_IsRationalOrNumber)
   <--
   [
     x:=N(x);
     Local(prec,result,n);
     Bind(prec,BuiltinPrecisionGet());
     If(IsZero(x),Bind(n,2),
     If(x>0,
       Bind(n,2+FloorN(N(FastLog(x)/FastLog(10)))),
       Bind(n,2+FloorN(N(FastLog(-x)/FastLog(10))))
       ));
     If(n>prec,BuiltinPrecisionSet(n));
     Bind(result,CeilN(x));
     BuiltinPrecisionSet(prec);
     result;
   ];
//   CeilN (N(x));

%/mathpiper



%mathpiper_docs,name="Ceil",categories="User Functions;Numbers (Operations)"
*CMD Ceil --- round a number upwards
*STD
*CALL
	Ceil(x)

*PARMS

{x} -- a number

*DESC

This function returns $Ceil(x)$, the smallest integer larger than or equal to $x$.

*E.G.

In> Ceil(1.1)
Result: 2;
In> Ceil(-1.1)
Result: -1;

*SEE Floor, Round
%/mathpiper_docs