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
34/**
35 * @brief return `true` if arg is `nil`, else `false`.
36 *
37 * Note that this doesn't really belong in `peano.h`, but after code cleanup it
38 * was the last thing remaining in either `boolean.c` or `boolean.h`, and it
39 * wasn't worth keeping two files around for one one-line macro.
40 *
41 * @param arg
42 * @return true if the sole argument is `nil`.
43 * @return false otherwise.
44 */
45#define truthy(arg)(!nilp(arg))
46
47bool zerop( struct cons_pointer arg );
48
49struct cons_pointer negative( struct cons_pointer arg );
50
51bool is_negative( struct cons_pointer arg );
52
53struct cons_pointer absolute( struct cons_pointer arg );
54
55long double to_long_double( struct cons_pointer arg );
56
57int64_t to_long_int( struct cons_pointer arg );
58
60 *frame, struct cons_pointer frame_pointer, struct
61 cons_pointer env );
62
63struct cons_pointer
64lisp_add( struct stack_frame *frame, struct cons_pointer frame_pointer,
65 struct cons_pointer env );
66
68 *frame,
69 struct cons_pointer frame_pointer, struct
70 cons_pointer env );
71
72struct cons_pointer
73lisp_multiply( struct stack_frame *frame,
74 struct cons_pointer frame_pointer, struct cons_pointer env );
75
76struct cons_pointer negative( struct cons_pointer arg );
77
78struct cons_pointer subtract_2( struct stack_frame *frame,
79 struct cons_pointer frame_pointer,
80 struct cons_pointer arg1,
81 struct cons_pointer arg2 );
82
83struct cons_pointer
84lisp_subtract( struct stack_frame *frame,
85 struct cons_pointer frame_pointer, struct cons_pointer env );
86
87struct cons_pointer
88lisp_divide( struct stack_frame *frame, struct cons_pointer frame_pointer,
89 struct cons_pointer env );
90
91struct cons_pointer lisp_ratio_to_real( struct stack_frame *frame,
92 struct cons_pointer frame_pointer,
93 struct cons_pointer env );
94
95#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:248
struct cons_pointer absolute(struct cons_pointer arg)
if arg is a number, return the absolute value of that number, else NIL
Definition peano.c:125
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:530
bool is_negative(struct cons_pointer arg)
does this arg point to a negative number?
Definition peano.c:99
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:797
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:572
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:683
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:698
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:165
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:494
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:355
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:585
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:217