📄 value.h
字号:
/* * value - definitions of general values and related routines used by calc * * Copyright (C) 1999-2006 David I. Bell * * Calc is open software; you can redistribute it and/or modify it under * the terms of the version 2.1 of the GNU Lesser General Public License * as published by the Free Software Foundation. * * Calc is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * A copy of version 2.1 of the GNU Lesser General Public License is * distributed with calc under the filename COPYING-LGPL. You should have * received a copy with calc; if not, write to Free Software Foundation, Inc. * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * @(#) $Revision: 29.11 $ * @(#) $Id: value.h,v 29.11 2006/08/20 15:01:30 chongo Exp $ * @(#) $Source: /usr/local/src/cmd/calc/RCS/value.h,v $ * * Under source code control: 1993/07/30 19:42:47 * File existed as early as: 1993 * * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ */#if !defined(__VALUE_H__)#define __VALUE_H__#if defined(CALC_SRC) /* if we are building from the calc source tree */# include "win32dll.h"# include "cmath.h"# include "config.h"# include "shs.h"# include "calcerr.h"# include "hash.h"# include "block.h"# include "nametype.h"# include "string.h"#else# include <calc/win32dll.h># include <calc/cmath.h># include <calc/config.h># include <calc/shs.h># include <calc/calcerr.h># include <calc/hash.h># include <calc/block.h># include <calc/nametype.h># include <calc/string.h>#endif#define MAXDIM 4 /* maximum number of dimensions in matrices */#define USUAL_ELEMENTS 4 /* usual number of elements for objects *//* * Flags to modify results from the printvalue routine. * These flags are OR'd together. */#define PRINT_NORMAL 0x00 /* print in normal manner */#define PRINT_SHORT 0x01 /* print in short format (no elements) */#define PRINT_UNAMBIG 0x02 /* print in non-ambiguous manner *//* * Definition of values of various types. */typedef struct value VALUE;typedef struct object OBJECT;typedef struct matrix MATRIX;typedef struct list LIST;typedef struct assoc ASSOC;typedef long FILEID;typedef struct rand RAND;typedef struct random RANDOM;/* * calc values * * See below for information on what needs to be added for a new type. */struct value { short v_type; /* type of value */ unsigned short v_subtype; /* other data related to some types */ union { /* types of values (see V_XYZ below) */ long vv_int; /* 1: small integer value */ NUMBER *vv_num; /* 2, 21: real number */ COMPLEX *vv_com; /* 3: complex number */ VALUE *vv_addr; /* 4, 18: address of variable value */ STRING *vv_str; /* 5, 20: string value */ MATRIX *vv_mat; /* 6: address of matrix */ LIST *vv_list; /* 7: address of list */ ASSOC *vv_assoc; /* 8: address of association */ OBJECT *vv_obj; /* 9: address of object */ FILEID vv_file; /* 10: id of opened file */ RAND *vv_rand; /* 11: additive 55 random state */ RANDOM *vv_random; /* 12: Blum random state */ CONFIG *vv_config; /* 13: configuration state */ HASH *vv_hash; /* 14: hash state */ BLOCK *vv_block; /* 15: memory block */ OCTET *vv_octet; /* 16, 19: octet addr (unsigned char) */ NBLOCK *vv_nblock; /* 17: named memory block */ } v_union;};/* * For ease in referencing */#define v_int v_union.vv_int#define v_file v_union.vv_file#define v_num v_union.vv_num#define v_com v_union.vv_com#define v_addr v_union.vv_addr#define v_str v_union.vv_str#define v_mat v_union.vv_mat#define v_list v_union.vv_list#define v_assoc v_union.vv_assoc#define v_obj v_union.vv_obj#define v_valid v_union.vv_int#define v_rand v_union.vv_rand#define v_random v_union.vv_random#define v_config v_union.vv_config#define v_hash v_union.vv_hash#define v_block v_union.vv_block#define v_octet v_union.vv_octet#define v_nblock v_union.vv_nblock/* * Value types. * * NOTE: The following files should be checked/adjusted for a new type: * * size.c - elm_count(), lsizeof() * help/size - update what the size() builtin will report * hash.c - hash_value() * quickhash.c - hashvalue() * value.c - freevalue(), copyvalue(), comparevalue(), * printvalue(), * and other as needed such as testvalue(), etc. * * There may be others, but at is at least a start. */#define V_NULL 0 /* null value */#define V_INT 1 /* normal integer */#define V_NUM 2 /* number */#define V_COM 3 /* complex number */#define V_ADDR 4 /* address of variable value */#define V_STR 5 /* address of string */#define V_MAT 6 /* address of matrix structure */#define V_LIST 7 /* address of list structure */#define V_ASSOC 8 /* address of association structure */#define V_OBJ 9 /* address of object structure */#define V_FILE 10 /* opened file id */#define V_RAND 11 /* address of additive 55 random state */#define V_RANDOM 12 /* address of Blum random state */#define V_CONFIG 13 /* configuration state */#define V_HASH 14 /* hash state */#define V_BLOCK 15 /* memory block */#define V_OCTET 16 /* octet (unsigned char) */#define V_NBLOCK 17 /* named memory block */#define V_VPTR 18 /* value address as pointer */#define V_OPTR 19 /* octet address as pointer */#define V_SPTR 20 /* string address as pointer */#define V_NPTR 21 /* number address as pointer */#define V_MAX 21 /* highest legal value */#define V_NOSUBTYPE 0 /* subtype has no meaning */#define V_NOASSIGNTO 1 /* protection status 1 */#define V_NONEWVALUE 2 /* protection status 2 */#define V_NONEWTYPE 4 /* protection status 4 */#define V_NOERROR 8 /* protection status 8 */#define V_NOCOPYTO 16 /* protection status 16 */#define V_NOREALLOC 32 /* protection status 32 */#define V_NOASSIGNFROM 64 /* protection status 64 */#define V_NOCOPYFROM 128 /* protection status 128 */#define V_PROTECTALL 256 /* protection status 256 */#define MAXPROTECT 511/* * At present protect(var, sts) determines bits in var->v_subtype * corresponding to 4 * sts. MAXPROTECT is the sum of the simple * (power of two) protection status values. */#define TWOVAL(a,b) ((a) << 5 | (b)) /* for switch of two values */#define NULL_VALUE ((VALUE *) 0)/* * value functions */extern DLL void freevalue(VALUE *vp);extern DLL void copyvalue(VALUE *vp, VALUE *vres);extern DLL void negvalue(VALUE *vp, VALUE *vres);extern DLL void addvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void subvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void mulvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void orvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void andvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void compvalue(VALUE *vp, VALUE *vres);extern DLL void xorvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void squarevalue(VALUE *vp, VALUE *vres);extern DLL void invertvalue(VALUE *vp, VALUE *vres);extern DLL void roundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void broundvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void setminusvalue(VALUE *, VALUE *, VALUE *);extern DLL void backslashvalue(VALUE *, VALUE *);extern DLL void contentvalue(VALUE *, VALUE *);extern DLL void hashopvalue(VALUE *, VALUE *, VALUE *);extern DLL void apprvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void intvalue(VALUE *vp, VALUE *vres);extern DLL void fracvalue(VALUE *vp, VALUE *vres);extern DLL void incvalue(VALUE *vp, VALUE *vres);extern DLL void decvalue(VALUE *vp, VALUE *vres);extern DLL void conjvalue(VALUE *vp, VALUE *vres);extern DLL void sqrtvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void rootvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void absvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void normvalue(VALUE *vp, VALUE *vres);extern DLL void shiftvalue(VALUE *v1, VALUE *v2, BOOL rightshift, VALUE *vres);extern DLL void scalevalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void powivalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void powervalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void divvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void quovalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL void modvalue(VALUE *v1, VALUE *v2, VALUE *v3, VALUE *vres);extern DLL BOOL testvalue(VALUE *vp);extern DLL BOOL comparevalue(VALUE *v1, VALUE *v2);extern DLL BOOL acceptvalue(VALUE *v1, VALUE *v2);extern DLL void relvalue(VALUE *v1, VALUE *v2, VALUE *vres);extern DLL void sgnvalue(VALUE *vp, VALUE *vres);extern DLL QCKHASH hashvalue(VALUE *vp, QCKHASH val);extern DLL void printvalue(VALUE *vp, int flags);extern DLL void printestr(VALUE *vp);extern DLL BOOL precvalue(VALUE *v1, VALUE *v2);extern DLL VALUE error_value(int e);extern DLL int set_errno(int e);extern DLL int set_errcount(int e);extern DLL long countlistitems(LIST *lp);extern DLL void addlistitems(LIST *lp, VALUE *vres);extern DLL void addlistinv(LIST *lp, VALUE *vres);extern DLL void copy2octet(VALUE *, OCTET *);extern DLL int copystod(VALUE *, long, long, VALUE *, long);extern DLL void protecttodepth(VALUE *, int, int);extern DLL void set_update(int);/* * Structure of a matrix. */struct matrix { long m_dim; /* dimension of matrix */ long m_size; /* total number of elements */ long m_min[MAXDIM]; /* minimum bound for indices */ long m_max[MAXDIM]; /* maximum bound for indices */ VALUE m_table[1]; /* actually varying length table */};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -