mirror of
https://github.com/jeremysrand/abCalc.git
synced 2024-11-23 08:35:43 +00:00
Add R2B and B2R operations
This commit is contained in:
parent
e69a032494
commit
5f26ba906d
@ -16,7 +16,8 @@ OPS_OBJS=ops/abCOp.o ops/abCOpAdd.o ops/abCOpSubtr.o ops/abCOpMult.o \
|
||||
ops/abCOpSwap.o ops/abCOpSin.o ops/abCOpCos.o ops/abCOpTan.o ops/abCOpAsin.o \
|
||||
ops/abCOpAcos.o ops/abCOpAtan.o ops/abCOpSq.o ops/abCOpSqrt.o ops/abCOpPi.o \
|
||||
ops/abCOpLog.o ops/abCOpAlog.o ops/abCOpLn.o ops/abCOpExp.o ops/abCOpSinh.o \
|
||||
ops/abCOpCosh.o ops/abCOpTanh.o ops/abCOpClear.o
|
||||
ops/abCOpCosh.o ops/abCOpTanh.o ops/abCOpClear.o ops/abCOpR2B.o \
|
||||
ops/abCOpB2R.o
|
||||
|
||||
SHELL_OBJS=abCMain.o $(CALC_OBJS) $(EXPR_OBJS) $(OPS_OBJS)
|
||||
|
||||
@ -88,4 +89,6 @@ ops/abCOpSinh.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExpRea
|
||||
ops/abCOpCosh.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExpReal.h ops/abCOpCosh.h
|
||||
ops/abCOpTanh.o: ops/abCOp.h abCError.h abCStack.h expr/abCExpr.h expr/abCExpReal.h ops/abCOpTanh.h
|
||||
ops/abCOpClear.o: ops/abCOp.h abCStack.h ops/abCOpClear.h
|
||||
ops/abCOpR2B.o: ops/abCOp.h abCStack.h abCError.h expr/abCExpr.h expr/abCExpReal.h expr/abCExprInt.h ops/abCOp.h ops/abCOpR2B.h
|
||||
ops/abCOpB2R.o: ops/abCOp.h abCStack.h abCError.h expr/abCExpr.h expr/abCExpReal.h expr/abCExprInt.h ops/abCOp.h ops/abCOpB2R.h
|
||||
|
||||
|
@ -45,6 +45,9 @@
|
||||
#include "ops/abCOpCosh.h"
|
||||
#include "ops/abCOpTanh.h"
|
||||
|
||||
#include "ops/abCOpR2B.h"
|
||||
#include "ops/abCOpB2R.h"
|
||||
|
||||
#include "ops/abCOpAnd.h"
|
||||
#include "ops/abCOpOr.h"
|
||||
#include "ops/abCOpXor.h"
|
||||
@ -105,6 +108,9 @@ void abCalcOpInit(void)
|
||||
abCalcOpCoshInit();
|
||||
abCalcOpTanhInit();
|
||||
|
||||
abCalcOpR2BInit();
|
||||
abCalcOpB2RInit();
|
||||
|
||||
abCalcOpAndInit();
|
||||
abCalcOpOrInit();
|
||||
abCalcOpXorInit();
|
||||
|
48
ops/abCOpB2R.c
Normal file
48
ops/abCOpB2R.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
abCOpB2R.c
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "abCError.h"
|
||||
#include "abCStack.h"
|
||||
|
||||
#include "expr/abCExpr.h"
|
||||
#include "expr/abCExpReal.h"
|
||||
#include "expr/abCExprInt.h"
|
||||
|
||||
#include "ops/abCOp.h"
|
||||
#include "ops/abCOpB2R.h"
|
||||
|
||||
|
||||
#define B2R_NAME "B2R"
|
||||
|
||||
|
||||
static void b2rExecute(void);
|
||||
|
||||
|
||||
void abCalcOpB2RInit(void)
|
||||
{
|
||||
abCalcOpRegister(B2R_NAME, b2rExecute);
|
||||
}
|
||||
|
||||
|
||||
void b2rExecute(void)
|
||||
{
|
||||
abCalcExpr result;
|
||||
int width;
|
||||
int topBit;
|
||||
AB_CALC_OP_ONE_ARG(B2R_NAME);
|
||||
|
||||
if (expr->type != abCalcExprTypeInt) {
|
||||
abCalcRaiseError(abCalcBadArgTypeError, B2R_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
abCalcExprRealSet(&result, (abCalcRealType)expr->u.integer);
|
||||
|
||||
abCalcStackExprPop(NULL);
|
||||
abCalcStackExprPush(&result);
|
||||
}
|
14
ops/abCOpB2R.h
Normal file
14
ops/abCOpB2R.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
abCOpB2R.h
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ABCOPB2R_H
|
||||
#define ABCOPB2R_H
|
||||
|
||||
|
||||
void abCalcOpB2RInit(void);
|
||||
|
||||
|
||||
#endif
|
48
ops/abCOpR2B.c
Normal file
48
ops/abCOpR2B.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
abCOpR2B.c
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "abCError.h"
|
||||
#include "abCStack.h"
|
||||
|
||||
#include "expr/abCExpr.h"
|
||||
#include "expr/abCExpReal.h"
|
||||
#include "expr/abCExprInt.h"
|
||||
|
||||
#include "ops/abCOp.h"
|
||||
#include "ops/abCOpR2B.h"
|
||||
|
||||
|
||||
#define R2B_NAME "R2B"
|
||||
|
||||
|
||||
static void r2bExecute(void);
|
||||
|
||||
|
||||
void abCalcOpR2BInit(void)
|
||||
{
|
||||
abCalcOpRegister(R2B_NAME, r2bExecute);
|
||||
}
|
||||
|
||||
|
||||
void r2bExecute(void)
|
||||
{
|
||||
abCalcExpr result;
|
||||
int width;
|
||||
int topBit;
|
||||
AB_CALC_OP_ONE_ARG(R2B_NAME);
|
||||
|
||||
if (expr->type != abCalcExprTypeReal) {
|
||||
abCalcRaiseError(abCalcBadArgTypeError, R2B_NAME);
|
||||
return;
|
||||
}
|
||||
|
||||
abCalcExprIntSet(&result, (abCalcIntType)expr->u.real);
|
||||
|
||||
abCalcStackExprPop(NULL);
|
||||
abCalcStackExprPush(&result);
|
||||
}
|
14
ops/abCOpR2B.h
Normal file
14
ops/abCOpR2B.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
abCOpR2B.h
|
||||
By: Jeremy Rand
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ABCOPR2B_H
|
||||
#define ABCOPR2B_H
|
||||
|
||||
|
||||
void abCalcOpR2BInit(void);
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user