mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-20 02:49:49 +01:00
Update modules/qrpn
This commit is contained in:
parent
136460e6b4
commit
a2111640af
1466
modules/qrpn/qrpn.c
1466
modules/qrpn/qrpn.c
File diff suppressed because it is too large
Load Diff
@ -1,34 +1,41 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
|
||||||
#include <complex.h>
|
#include <complex.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* reasonably large fixed stack size given this is not a turing complete implemetation */
|
||||||
|
#define QRPN_STACK_SIZE_MAX 32
|
||||||
|
|
||||||
|
/* not going to change in this unverse */
|
||||||
#define BASEUNITS 7
|
#define BASEUNITS 7
|
||||||
|
|
||||||
struct quantity {
|
struct quantity {
|
||||||
/* this is the only time you will ever catch me using double complex */
|
/* this is the only time you will ever catch me using double complex */
|
||||||
double complex value;
|
double complex value;
|
||||||
int8_t units[BASEUNITS]; /* metre, kilogram, second, ampere, kelvin, candela, mol */
|
int8_t units[BASEUNITS]; /* metre, kilogram, second, ampere, kelvin, candela, mol */
|
||||||
uint8_t flags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define QRPN_NOERR 0
|
/* mutate the stack, initially of size S, according to the current token, and return either the nonnegative new size S or a negative error code, which can be passed to qrpn_strerror to obtain a pointer to human-readable error string */
|
||||||
#define QRPN_ERROR_NOT_ENOUGH_STACK 1
|
int qrpn_evaluate_token(struct quantity * stack, int S, const char * const token);
|
||||||
#define QRPN_ERROR_INCONSISTENT_UNITS 2
|
|
||||||
#define QRPN_ERROR_MUST_BE_INTEGER 3
|
|
||||||
#define QRPN_ERROR_TOKEN_UNRECOGNIZED 4
|
|
||||||
#define QRPN_ERROR_RATIONAL_NOT_IMPLEMENTED 5
|
|
||||||
#define QRPN_ERROR_MUST_BE_UNITLESS 6
|
|
||||||
#define QRPN_ERROR_DOMAIN 7
|
|
||||||
#define QRPN_ERROR_DIMENSION_OVERFLOW 8
|
|
||||||
#define QRPN_WAS_A_UNIT 9
|
|
||||||
|
|
||||||
#define FLAG_UNIT_ENTERS_AS_OPERAND 1
|
/* same, but operate on a temporary copy of the input and do not mutate the original */
|
||||||
#define FLAG_SI_BASE_UNIT 4
|
int qrpn_try_token(const struct quantity stack[static QRPN_STACK_SIZE_MAX], const int S, const char * const token);
|
||||||
#define FLAG_SI_DERIVED_UNIT 8
|
|
||||||
|
|
||||||
int qrpn_evaluate_token(struct quantity ** stack_p, size_t * S_p, const char * const token);
|
/* given the value returned from a function above, return a pointer to a string literal */
|
||||||
char * qrpn_error_string(const int status);
|
char * qrpn_strerror(const int status);
|
||||||
void fprintf_stack(FILE * fh, struct quantity * stack, const size_t S);
|
|
||||||
|
/* utility functions */
|
||||||
|
void fprintf_stack(FILE * fh, struct quantity * stack, const int S);
|
||||||
void fprintf_quantity(FILE * fh, const struct quantity quantity);
|
void fprintf_quantity(FILE * fh, const struct quantity quantity);
|
||||||
int qrpn_try_token(const struct quantity * const stack, const size_t S, const char * const token);
|
|
||||||
|
/* status codes returned by qrpn_evaluate_token */
|
||||||
|
#define QRPN_ERROR_NOT_ENOUGH_STACK -1
|
||||||
|
#define QRPN_ERROR_INCONSISTENT_UNITS -2
|
||||||
|
#define QRPN_ERROR_MUST_BE_INTEGER -3
|
||||||
|
#define QRPN_ERROR_TOKEN_UNRECOGNIZED -4
|
||||||
|
#define QRPN_ERROR_RATIONAL_NOT_IMPLEMENTED -5
|
||||||
|
#define QRPN_ERROR_MUST_BE_UNITLESS -6
|
||||||
|
#define QRPN_ERROR_DOMAIN -7
|
||||||
|
#define QRPN_ERROR_DIMENSION_OVERFLOW -8
|
||||||
|
#define QRPN_ERROR_TOO_MUCH_STACK -9
|
||||||
|
#define QRPN_ERROR_UNMATCHED_CONTROL_STATEMENT -10
|
||||||
|
#define QRPN_NOT_A_UNIT -11
|
||||||
|
Loading…
Reference in New Issue
Block a user