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

Implements the OP_ISQRT opcode for integer square root (floor). More...

Go to the source code of this file.

Functions

 if (!((v.type==VAL_INT)||(v.type==VAL_FLOAT)))
 if (a<=0)
 while (bit, n)
 free_value (v)
 push_value (vm, make_int(r))

Variables

case OP_ISQRT
int64_t a = (v.type == VAL_INT) ? v.i : (int64_t)v.d
uint64_t n = (uint64_t)a
uint64_t x = 0
uint64_t bit = (uint64_t)1 << 62
int64_t r = (int64_t)x
 break

Detailed Description

Implements the OP_ISQRT opcode for integer square root (floor).

Behavior:

  • Pops one numeric operand (int or float), converts to int64.
  • Computes floor(sqrt(max(0, x))) as an integer without floating point.
  • Pushes VAL_INT result.

Stack effect:

  • Pop: x
  • Push: isqrt(x)

Types:

  • Accepts VAL_INT and VAL_FLOAT; others cause a runtime error.

Definition in file isqrt.c.

Function Documentation

◆ free_value()

free_value(v)
Here is the caller graph for this function:

◆ if() [1/2]

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

Definition at line 29 of file isqrt.c.

◆ if() [2/2]

if(a<=0)

Definition at line 34 of file isqrt.c.

Here is the call graph for this function:

◆ push_value()

push_value(vm,
make_int(r) )
Here is the caller graph for this function:

◆ while()

while(bit,
n )

Definition at line 43 of file isqrt.c.

Variable Documentation

◆ a

int64_t a = (v.type == VAL_INT) ? v.i : (int64_t)v.d

Definition at line 33 of file isqrt.c.

◆ bit

uint64_t bit = (uint64_t)1 << 62

Definition at line 42 of file isqrt.c.

◆ break

break

Definition at line 57 of file isqrt.c.

◆ n

uint64_t n = (uint64_t)a

Definition at line 40 of file isqrt.c.

◆ OP_ISQRT

case OP_ISQRT

Definition at line 27 of file isqrt.c.

◆ r

int64_t r = (int64_t)x

Definition at line 54 of file isqrt.c.

◆ x

uint64_t x = 0

Definition at line 41 of file isqrt.c.