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

Implements the OP_FLOOR opcode using C99 math.h floor(). More...

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

Go to the source code of this file.

Functions

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

Variables

case OP_FLOOR
 else
 break

Detailed Description

Implements the OP_FLOOR opcode using C99 math.h floor().

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

Behavior:

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

Stack effect:

  • Pop: x
  • Push: floor(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.9] → Output stack: [2]
  • Input stack: [-2.1] → Output stack: [-3]

Definition in file floor.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

if(v.type = VAL_INT)

Definition at line 41 of file floor.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 62 of file floor.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: FLOOR 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 floor.c.

◆ OP_FLOOR

case OP_FLOOR

Definition at line 39 of file floor.c.