Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
peano.h
Go to the documentation of this file.
1/*
2 * peano.h
3 *
4 * Basic peano arithmetic
5 *
6 * (c) 2017 Simon Brooke <simon@journeyman.cc>
7 * Licensed under GPL version 2.0, or, at your option, any later version.
8 */
9
10
11#ifndef PEANO_H
12#define PEANO_H
13
15
16/**
17 * The maximum value we will allow in an integer cell: one less than 2^60:
18 * (let ((s (make-string-output-stream)))
19 * (format s "0x0~XL" (- (expt 2 60) 1))
20 * (string-downcase (get-output-stream-string s)))
21 * "0x0fffffffffffffffl"
22 *
23 * So left shifting and right shifting by 60 bits is correct.
24 */
25#define MAX_INTEGER ((__int128_t)0x0fffffffffffffffL)
26#define INT_CELL_BASE ((__int128_t)MAX_INTEGER + 1) // ((__int128_t)0x1000000000000000L)
27
28/**
29 * @brief Number of value bits in an integer cell
30 *
31 */
32#define INTEGER_BIT_SHIFT (60)
33
34bool zerop( struct cons_pointer arg );
35
36struct cons_pointer negative( struct cons_pointer arg );
37
38bool is_negative( struct cons_pointer arg );
39
40struct cons_pointer absolute( struct cons_pointer arg );
41
42long double to_long_double( struct cons_pointer arg );
43
44int64_t to_long_int( struct cons_pointer arg );
45
47 *frame, struct cons_pointer frame_pointer, struct
48 cons_pointer env );
49
50struct cons_pointer
51lisp_add( struct stack_frame *frame, struct cons_pointer frame_pointer,
52 struct cons_pointer env );
53
55 *frame,
56 struct cons_pointer frame_pointer, struct
57 cons_pointer env );
58
59struct cons_pointer
60lisp_multiply( struct stack_frame *frame,
61 struct cons_pointer frame_pointer, struct cons_pointer env );
62
63struct cons_pointer negative( struct cons_pointer arg );
64
65struct cons_pointer subtract_2( struct stack_frame *frame,
66 struct cons_pointer frame_pointer,
67 struct cons_pointer arg1,
68 struct cons_pointer arg2 );
69
70struct cons_pointer
71lisp_subtract( struct stack_frame *frame,
72 struct cons_pointer frame_pointer, struct cons_pointer env );
73
74struct cons_pointer
75lisp_divide( struct stack_frame *frame, struct cons_pointer frame_pointer,
76 struct cons_pointer env );
77
78struct cons_pointer lisp_ratio_to_real( struct stack_frame *frame,
79 struct cons_pointer frame_pointer,
80 struct cons_pointer env );
81
82#endif /* PEANO_H */
An indirect pointer to a cons cell.
A stack frame.
struct cons_pointer lisp_absolute(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: calculate the absolute value of a number.
Definition peano.c:207
struct cons_pointer absolute(struct cons_pointer arg)
Definition peano.c:89
struct cons_pointer negative(struct cons_pointer arg)
return a cons_pointer indicating a number which is the 0 - the number indicated by arg.
Definition peano.c:489
bool is_negative(struct cons_pointer arg)
does this arg point to a negative number?
Definition peano.c:70
struct cons_pointer lisp_ratio_to_real(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: return a real (approcimately) equal in value to the ratio which is the first argument.
Definition peano.c:755
struct cons_pointer lisp_is_negative(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Function: is this number negative?
Definition peano.c:531
struct cons_pointer lisp_subtract(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Subtract one number from another.
Definition peano.c:640
struct cons_pointer lisp_divide(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Divide one number by another.
Definition peano.c:655
long double to_long_double(struct cons_pointer arg)
Return the closest possible binary64 representation to the value of this arg, expected to be an integ...
Definition peano.c:124
struct cons_pointer lisp_multiply(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Multiply an indefinite number of numbers together.
Definition peano.c:453
struct cons_pointer lisp_add(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer env)
Add an indefinite number of numbers together.
Definition peano.c:314
struct cons_pointer subtract_2(struct stack_frame *frame, struct cons_pointer frame_pointer, struct cons_pointer arg1, struct cons_pointer arg2)
return a cons_pointer indicating a number which is the result of subtracting the number indicated by ...
Definition peano.c:544
bool zerop(struct cons_pointer arg)
return true if this arg points to a number whose value is zero.
Definition peano.c:41
int64_t to_long_int(struct cons_pointer arg)
Return the closest possible int64_t representation to the value of this arg, expected to be an intege...
Definition peano.c:176