Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
ceil.c File Reference

Implements the OP_CEIL opcode using C99 math.h ceil(). More...

#include <math.h>
Include dependency graph for ceil.c:

Go to the source code of this file.

Functions

 if (v.type==VAL_INT)
 exit (1)

Variables

case OP_CEIL
 else
 break

Detailed Description

Implements the OP_CEIL opcode using C99 math.h ceil().

VM opcode snippet included by vm.c. Provides numeric ceiling operation.

Behavior:

  • Pops one numeric operand (int or float) from the stack.
  • Applies ceil(x) in double precision.
  • If the result is an exact 64-bit integer, pushes VAL_INT; otherwise VAL_FLOAT.

Stack effect:

  • Pop: x
  • Push: ceil(x)

Types:

  • Accepts VAL_INT and VAL_FLOAT.
  • Other types cause a runtime error.

Errors:

  • Exits with an error message if the operand is not a number.

Example:

  • Input stack: [2.1] → Output stack: [3]
  • Input stack: [-2.1] → Output stack: [-2]

Definition in file ceil.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

else if(v.type = VAL_INT)

Definition at line 41 of file ceil.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 62 of file ceil.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: CEIL expects number, got %s\n", value_type_name(v.type))
Value v
Definition cast.c:22
#define fprintf
Definition vm.c:200

Definition at line 58 of file ceil.c.

◆ OP_CEIL

case OP_CEIL

Definition at line 39 of file ceil.c.