-
Notifications
You must be signed in to change notification settings - Fork 10
/
MalNumber.HC
44 lines (37 loc) · 743 Bytes
/
MalNumber.HC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Functions for working with number Malvals
#ifndef MALNUMBER_HC
#define MALNUMBER_HC
#include "Util.HC"
#include "PArray.HC"
#include "Types.HC"
#include "Util.HC"
BOOL MalIsNumber(Malval *m)
{
NullCheck(m, "malval");
if (m->_tag == ATOM)
return m->_atom->_tag == ATOM_NUMBER;
else return FALSE;
}
Malval *MalNumberMk(INT n)
{
Malval *m = _MalMk;
m->_tag = ATOM;
Atom *a = MAlloc(sizeof(Atom));
a->_tag = ATOM_NUMBER;
a->_num = n;
m->_atom = a;
m->_metadata = MalNilMk;
return m;
}
INT MalIntOfNumber(Malval *m)
{
NullCheck(m, "malval");
if (m->_tag != ATOM) {
throws("expected number");
}
if (m->_atom->_tag != ATOM_NUMBER) {
throws("expected number");
}
return m->_atom->_num;
}
#endif