Post Scarcity
A prototype for a post scarcity programming environment
Loading...
Searching...
No Matches
equal.c File Reference
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include "arith/integer.h"
#include "arith/peano.h"
#include "arith/ratio.h"
#include "debug.h"
#include "memory/conspage.h"
#include "memory/consspaceobject.h"
#include "memory/vectorspace.h"
#include "ops/equal.h"
#include "ops/intern.h"
Include dependency graph for equal.c:

Go to the source code of this file.

Functions

bool end_of_string (struct cons_pointer string)
 Some strings will be null terminated and some will be NIL terminated... ooops!
 
bool eq (struct cons_pointer a, struct cons_pointer b)
 Shallow, and thus cheap, equality: true if these two objects are the same object, else false.
 
bool equal (struct cons_pointer a, struct cons_pointer b)
 Deep, and thus expensive, equality: true if these two objects have identical structure, else false.
 
bool equal_integer_number (struct cons_pointer a, struct cons_pointer b)
 Private function, don't use.
 
bool equal_integer_real (struct cons_pointer a, struct cons_pointer b)
 Private function, don't use.
 
bool equal_ld_ld (long double a, long double b)
 compare two long doubles and returns true if they are the same to within a tolerance of one part in a billion.
 
bool equal_map_map (struct cons_pointer a, struct cons_pointer b)
 equality of two map-like things.
 
bool equal_number_number (struct cons_pointer a, struct cons_pointer b)
 Private function, don't use.
 
bool equal_real_number (struct cons_pointer a, struct cons_pointer b)
 Private function, don't use.
 
bool equal_vector_vector (struct cons_pointer a, struct cons_pointer b)
 equality of two vector-space things.
 
bool same_type (struct cons_pointer a, struct cons_pointer b)
 True if the objects at these two cons pointers have the same tag, else false.
 

Function Documentation

◆ end_of_string()

bool end_of_string ( struct cons_pointer  string)

Some strings will be null terminated and some will be NIL terminated... ooops!

Parameters
stringthe string to test
Returns
true if it's the end of a string.

Definition at line 51 of file equal.c.

References nilp, cons_space_object::payload, and pointer2cell.

◆ eq()

bool eq ( struct cons_pointer  a,
struct cons_pointer  b 
)

Shallow, and thus cheap, equality: true if these two objects are the same object, else false.

Definition at line 28 of file equal.c.

References cons_pointer::offset, and cons_pointer::page.

Referenced by equal(), equal_number_number(), equal_vector_vector(), lisp_add(), lisp_eq(), lisp_repl(), make_ratio(), and release_integer().

◆ equal()

bool equal ( struct cons_pointer  a,
struct cons_pointer  b 
)

◆ equal_integer_number()

bool equal_integer_number ( struct cons_pointer  a,
struct cons_pointer  b 
)

Private function, don't use.

It depends on its arguments being numbers and doesn't sanity check them.

Parameters
aa lisp integer – if it isn't an integer, things will break.
ba lisp number.
Returns
true if the two numbers have equal value.
false if they don't.

Definition at line 124 of file equal.c.

References DEBUG_ARITH, debug_print(), debug_print_object(), debug_printf(), equal_integer_integer(), equal_integer_real(), INTEGERTV, pointer2cell, RATIOTV, REALTV, and cons_space_object::tag.

Referenced by equal_number_number().

◆ equal_integer_real()

bool equal_integer_real ( struct cons_pointer  a,
struct cons_pointer  b 
)

Private function, don't use.

It depends on its arguments being numbers and doesn't sanity check them.

Parameters
aa lisp integer – if it isn't an integer, things will break.
ba lisp real – if it isn't a real, things will break.
Returns
true if the two numbers have equal value.
false if they don't.

Definition at line 91 of file equal.c.

References DEBUG_ARITH, debug_print(), debug_print_object(), debug_printf(), equal_ld_ld(), nilp, cons_space_object::payload, and pointer2cell.

Referenced by equal_integer_number(), and equal_real_number().

◆ equal_ld_ld()

bool equal_ld_ld ( long double  a,
long double  b 
)

compare two long doubles and returns true if they are the same to within a tolerance of one part in a billion.

Parameters
a
b
Returns
true if a and b are equal to within one part in a billion.
false otherwise.

Definition at line 65 of file equal.c.

References DEBUG_ARITH, and debug_printf().

Referenced by equal_integer_real(), and equal_real_number().

◆ equal_map_map()

bool equal_map_map ( struct cons_pointer  a,
struct cons_pointer  b 
)

equality of two map-like things.

The list returned by keys on a map-like thing is not sorted, and is not guaranteed always to come out in the same order. So equality is established if:

  1. the length of the keys list is the same; and
  2. the value of each key in the keys list for map a is the same in map a and in map b.

Private function, do not use outside this file, WILL NOT work unless both arguments are VECPs.

Parameters
aa pointer to a vector space object.
banother pointer to a vector space object.
Returns
true if the two objects have the same logical structure.
false otherwise.

Definition at line 265 of file equal.c.

References c_car(), c_cdr(), c_length(), equal(), hashmap_get(), hashmap_keys(), and nilp.

Referenced by equal_vector_vector().

◆ equal_number_number()

bool equal_number_number ( struct cons_pointer  a,
struct cons_pointer  b 
)

Private function, don't use.

It depends on its arguments being numbers and doesn't sanity check them.

Parameters
aa number
ba number
Returns
true if the two numbers have equal value.
false if they don't.

Definition at line 199 of file equal.c.

References DEBUG_ARITH, debug_print(), debug_print_object(), debug_printf(), eq(), equal_integer_number(), equal_ratio_ratio(), equal_real_number(), INTEGERTV, pointer2cell, RATIOTV, REALTV, and cons_space_object::tag.

Referenced by equal().

◆ equal_real_number()

bool equal_real_number ( struct cons_pointer  a,
struct cons_pointer  b 
)

Private function, don't use.

It depends on its arguments being numbers and doesn't sanity check them.

Parameters
aa lisp real – if it isn't an real, things will break.
ba lisp number.
Returns
true if the two numbers have equal value.
false if they don't.

Definition at line 159 of file equal.c.

References c_ratio_to_ld(), DEBUG_ARITH, debug_print(), debug_print_object(), debug_printf(), equal_integer_real(), equal_ld_ld(), INTEGERTV, cons_space_object::payload, pointer2cell, RATIOTV, REALTV, and cons_space_object::tag.

Referenced by equal_number_number().

◆ equal_vector_vector()

bool equal_vector_vector ( struct cons_pointer  a,
struct cons_pointer  b 
)

equality of two vector-space things.

Expensive, but we need to be able to check for equality of at least hashmaps and namespaces.

Private function, do not use outside this file, not guaranteed to work unless both arguments are VECPs pointing to map like things.

Parameters
aa pointer to a vector space object.
banother pointer to a vector space object.
Returns
true if the two objects have the same logical structure.
false otherwise.

Definition at line 299 of file equal.c.

References eq(), equal_map_map(), HASHTV, vector_space_object::header, NAMESPACETV, pointer_to_vso, vector_space_header::tag, and vectorp.

Referenced by equal().

◆ same_type()

bool same_type ( struct cons_pointer  a,
struct cons_pointer  b 
)

True if the objects at these two cons pointers have the same tag, else false.

Parameters
aa pointer to a cons-space object;
banother pointer to a cons-space object.
Returns
true if the objects at these two cons pointers have the same tag, else false.

Definition at line 39 of file equal.c.

References pointer2cell, and cons_space_object::tag.

Referenced by equal().