Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
log.c File Reference

Implements the OP_LOG opcode using C99 math.h log() (natural logarithm). More...

#include <math.h>
Include dependency graph for log.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Variables

case OP_LOG
 else
 break

Detailed Description

Implements the OP_LOG opcode using C99 math.h log() (natural logarithm).

Behavior:

  • Pops one numeric operand (int or float).
  • If x <= 0, pushes NaN to indicate domain error; otherwise pushes ln(x).
  • Result type is VAL_FLOAT.

Stack effect:

  • Pop: x
  • Push: ln(x) | NaN

Types:

  • Accepts VAL_INT and VAL_FLOAT; errors on others.

Definition in file log.c.

Function Documentation

◆ exit()

exit ( 1 )

◆ if()

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

Definition at line 31 of file log.c.

Variable Documentation

◆ break

break

Definition at line 45 of file log.c.

◆ else

else
Initial value:
{
fprintf(stderr, "Runtime type error: LOG expects number, got %s\n", value_type_name(v.type))
Value v
Definition cast.c:22
static const char * value_type_name(ValueType t)
Get a human-readable name for a ValueType.
Definition vm.c:318
#define fprintf
Definition vm.c:200

Definition at line 41 of file log.c.

◆ OP_LOG

case OP_LOG

Definition at line 29 of file log.c.