Fun
0.41.5
The programming language that makes You have fun
Main Page
Data Structures
Files
File List
Globals
Loading...
Searching...
No Matches
src
vm
math
sign.c
Go to the documentation of this file.
1
/*
2
* This file is part of the Fun programming language.
3
* https://fun-lang.xyz/
4
*
5
* Copyright 2026 Johannes Findeisen <you@hanez.org>
6
* Licensed under the terms of the Apache-2.0 license.
7
* https://opensource.org/license/apache-2-0
8
*/
9
14
15
case
OP_SIGN
: {
16
Value
v
= pop_value(vm);
17
int
out
= 0;
18
if
(
v
.type ==
VAL_INT
) {
19
out
= (
v
.i > 0) - (
v
.i < 0);
20
}
else
if
(
v
.type ==
VAL_FLOAT
) {
21
if
(
v
.d > 0.0)
22
out
= 1;
23
else
if
(
v
.d < 0.0)
24
out
= -1;
25
else
26
out
= 0;
27
}
else
{
28
fprintf
(stderr,
"Runtime type error: SIGN expects number, got %s\n"
, value_type_name(
v
.type));
29
exit
(1);
30
}
31
free_value
(
v
);
32
push_value
(vm,
make_int
(
out
));
33
break
;
34
}
out
Value out
Definition
apop.c:38
OP_SIGN
@ OP_SIGN
Definition
bytecode.h:271
v
Value v
Definition
cast.c:22
push_value
push_value(vm, make_int(out))
free_value
free_value(v)
Value
Tagged union representing a Fun value.
Definition
value.h:68
make_int
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition
value.c:51
VAL_INT
@ VAL_INT
Definition
value.h:51
VAL_FLOAT
@ VAL_FLOAT
Definition
value.h:58
fprintf
#define fprintf
Definition
vm.c:200
exit
#define exit(code)
Definition
vm.c:230
Generated on
for Fun by
1.16.1