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

Implements the OP_COS opcode using C99 math.h cos(). More...

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

Go to the source code of this file.

Functions

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

Variables

case OP_COS
 else
 break

Detailed Description

Implements the OP_COS opcode using C99 math.h cos().

VM opcode snippet included by vm.c. Provides cosine function.

Behavior:

  • Pops one numeric operand (int or float) from the stack.
  • Computes cos(x) in double precision.
  • Always pushes a VAL_FLOAT result.

Stack effect:

  • Pop: x
  • Push: cos(x)

Types:

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

Example:

  • Input [0] → Output [1.0]

Definition in file cos.c.

Function Documentation

◆ exit()

exit(1)

◆ if()

if(v.type = VAL_INT || v.type == VAL_FLOAT)

Definition at line 37 of file cos.c.

Here is the call graph for this function:

Variable Documentation

◆ break

break

Definition at line 46 of file cos.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: COS 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 42 of file cos.c.

◆ OP_COS

case OP_COS

Definition at line 35 of file cos.c.