Author Topic: absolutely critical that you play with this small stand alone app  (Read 10634 times)

0 Members and 1 Guest are viewing this topic.

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
absolutely critical that you play with this small stand alone app
I would try, but then I'd actually have to do the math to test if the responses are correct. And I'm not that confident in my own maths skills. :p
Freelance Modeler | Amateur Artist

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
it's called a calculator.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
absolutely critical that you play with this small stand alone app
Works good now, I tried mine and a few other equations posted in this thread and all worked.

Doesn't seem to support negative numbers too well:
NOTE: Spacing is important and I tried to be exact, since it seems to break stuff.

Quote
-5 + 3
"3 = 3"

3 + -5
"-5 = -5"

3+-5
"3+-5 = 8"

(3)+(-5)
"(3)+(-5)" = -2

3 + 4
"4 = 4"

4 + 3
"3 = 3"

(3) + (4)
"(4) = 4"


3+4
"3+4 = 7"


The % operator also behaves oddly:
Quote
4%3+7
"4%3+7 = 0"

(4%3)+7
"(4%3)+7 = 4"


Edit: Sent the link to a friend.

Quote
3^-2
"3^-2 = 9"

3^(-2)
"3^(-2) = 0.111111"
« Last Edit: April 27, 2005, 11:07:48 pm by 374 »
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
I don't have modulus in yet, I'm suprized that worked at all.

I should have mentioned only inital rudimentery suport for negitive mumbers has been added, you'd be suprized how complicated it is to figure out weather a '-' means subtract or negate. right now it looks to see if the charicter on the other side of the - sign is a NULL or a ( indicateing that it's at the start of an expression, I guess it should also see if there are any opperateors there.

see if the general mechanisms for positive numbers works corectly while I work on getting this working
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Taristin

  • Snipes
  • 213
  • BlueScalie
    • Skelkwank Shipyards
absolutely critical that you play with this small stand alone app
Quote
Originally posted by Bobboau
it's called a calculator.


Eh? Whassat?
Freelance Modeler | Amateur Artist

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
magic

ok and now I have version 3 uploaded, I real realy think I got negitive numbers working now :)
wait a secon I just DLed it and it's weird
« Last Edit: April 27, 2005, 11:19:20 pm by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
absolutely critical that you play with this small stand alone app
First impression (Ignore the cutoffedness, that'd be the stupid dos box):
Code: [Select]
3 + 4

3 = 3
if this is not corect, please tell me and provid

enter another expression or type exit to do so:

+ = 0
if this is not corect, please tell me and provid

enter another expression or type exit to do so:

4 = 4
if this is not corect, please tell me and provid


3+-5 still doesn't work properly...
3^-2 still doesn't work properly...
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
ok, new post new atachment

[note to self]don't modify atachments

use this atachment, it looks like when I changed the old exe it got corupted or something, a fresh upload should work good, I know for a fact those expressions are all working on my machine
« Last Edit: April 27, 2005, 11:26:10 pm by 57 »
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
absolutely critical that you play with this small stand alone app
Both of the bottom equations work now, although it keeps thinking that a space = a new equation.

*Tests some more*

Edit:

-(2^-(3)+1)-3 = 10
2^-(3) = 8
-(9)-3 = 6
3-(9)-3 = -9
« Last Edit: April 27, 2005, 11:33:58 pm by 374 »
-C

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
"although it keeps thinking that a space = a new equation"
thats a..ehh..... undocumented feature! er..yeah that's it, not a bug...

but seriously, hmm, interesting, that must be doind that at a high level, higher than the classes I'm testing, because its giveing the whole output thing.
seems to indeed be a 'feature' of cin and/or string.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
hmm hadn't thought of that, looks like I'm going to have to make a class of unary operators also.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
absolutely critical that you play with this small stand alone app
ok, I need to sleep, if you want to play with this tonight, here is the full source for that console app. seems like I'm going to have to pre process the input infix data and find unary '-'s and give them some specal tolken. then add a whole new class of opperators that only have one operand, I was going to need to do this eventualy to suport sin, cos, (ect).
sleepy time :)

Code: [Select]
#include
#include
#include
#include
#include

using namespace std;

struct ship{
float a;
};

class variable{
public:
virtual float value(ship*shipp=NULL) = 0;
};

class constant:public variable{
float val;
public:
constant(float in):val(in){};
float value(ship*shipp=NULL){return val;};
};


class operate:public variable{
protected:
variable *operand1, *operand2;
public:
virtual float value(ship*shipp=NULL) = 0;
operate(variable*op1, variable*op2){operand1 = op1; operand2 = op2;}
~operate(){if(operand1)delete operand1; if(operand2)delete operand2;}
};


class add:public operate{
public:
add(variable*op1, variable*op2):operate(op1,op2){}
float value(ship*shipp=NULL){return operand1->value(shipp) + operand2->value(shipp);}
};

class sub:public operate{
public:
sub(variable*op1, variable*op2):operate(op1,op2){}
float value(ship*shipp=NULL){return operand1->value(shipp) - operand2->value(shipp);};
};

class divide:public operate{
public:
divide(variable*op1, variable*op2):operate(op1,op2){}
float value(ship*shipp=NULL){return operand1->value(shipp) / operand2->value(shipp);};
};

class power:public operate{
public:
power(variable*op1, variable*op2):operate(op1,op2){}
float value(ship*shipp=NULL){return(float)pow(operand1->value(shipp), operand2->value(shipp));};
};

class mult:public operate{
public:
mult(variable*op1, variable*op2):operate(op1,op2){}
float value(ship*shipp=NULL){return operand1->value(shipp) * operand2->value(shipp);};
};


class expression:public variable{
int n_var; //number of variables in the expression
variable *head; //the head of the expression

void postfix(string&);
variable* parse_next(char*&);
variable* get_ship_variable(char**);
public:
expression(char*);
~expression(){for(int i = 0;i float value(ship*shipp=NULL);
};

/*
variable* con = new constant(1.0f);
variable* op = new add(con,con);
*/


expression::expression(char* in_str):n_var(0),head(NULL){
string str = in_str;
postfix(str);
char* is = new char[str.length()+1];
char* os = is;
strcpy(is, str.c_str());
head = parse_next(is);
delete[]os;
}

variable* expression::parse_next(char*&in_str){
//kill any noise
while((*in_str == ' ' || *in_str == ' ') && *in_str != char(0))in_str++;

char ship_idnt[] = "ship:";
char op_char[] = "+-/*^";
if(!strcmp(in_str,ship_idnt)){
(*in_str)+=strlen(ship_idnt);
//it's a ship variable
return get_ship_variable(&in_str);
}else{
//it's a constant, or an opporateor
if(strchr(op_char, *in_str) && *(in_str+1) == ','){
//it must be an operator
char o = *in_str++;
if(*in_str == ',')in_str++;

variable*a = parse_next(in_str);
variable*b = parse_next(in_str);

switch(o){
case '+':return new add(a,b);
case '-':return new sub(a,b);
case '*':return new mult(a,b);
case '/':return new divide(a,b);
case '^':return new power(a,b);
}
}else{
//it must be a constant
char *str = in_str;
while(*(in_str) != ',' && *in_str != 0)in_str++;
if(*in_str == ',')in_str++;
return  new constant(atof(str));
}
}

return NULL;
}

variable* expression::get_ship_variable(char**){
return new constant(0.0f);
}

inline int get_value(char c){
switch(c){
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
case '^':
return 3;
default:return -1;
}
}

bool is_value(char c){
if(c >= '0' && c <= '9')return true;
if(c == '.')return true;
return false;
}
void fix_implied_mult(string &str){
for(int i = 1; i< str.length(); i++){
if(str[i] == '('){
if(!get_value(str[i-1]))
str.insert(i,"*");
}
}
}

void reverse(string&s){
string out = "";
int l = s.length();
string temp = "";
for(int i = 0; i for(i; i temp += s[i];
if(!is_value(s[i]) || !is_value(s[i+1]))break;
}
out.insert(0,temp);
temp = "";
}
s = out;
}

void expression::postfix(string& str){
string s = str;
fix_implied_mult(s);
stack op_stack;

string out;
reverse(s);

int i = 0;
while(s[i]){
if(is_value(s[i])){
int sidx = i;

while(is_value(s[i]))out+=s[i++];

if(s[i] == '-' && (s[i+1] == 0 || s[i+1] == '(' || get_value(s[i+1]) != -1)){
out+="-";
i++;
}

out+=',';
}else if(s[i] == ')'){
op_stack.push(s[i++]);
}else if(s[i] == '('){
while(op_stack.top() != ')'){
out+=op_stack.top();
op_stack.pop();
out+=',';
}
op_stack.pop();
i++;
}else{
int v = get_value(s[i]);
if(v){
//it's an opperator
if(op_stack.empty() || op_stack.top() == ')' || get_value(op_stack.top()) <= v){
op_stack.push(s[i++]);
}else{
while(!op_stack.empty() && get_value(op_stack.top()) > v){
out+=op_stack.top();
op_stack.pop();
out+=',';
}
op_stack.push(s[i++]);
}
}
}
}
while(!op_stack.empty()){out+=op_stack.top(); op_stack.pop(); out+=',';}
out.resize(out.length()-1);
reverse(out);

str = out;
}

float expression::value(ship*shipp){
return head->value(shipp);
}


void main(){
string str = "";
// string str = "(1+2)*(3+4)*(5+6)";
// string str = "1+(2+3*4^(5-3)-7)*3";
// string str = "1+2+3*4^5-6-7*8";
// string str = "1+2*3+4";
// string str = "1*(2+3)";
// string str = "2*3/(2-1)+5*(4-1)";
// string str = "49*49-49";

cout << "enter an expression or type exit to do so\n";
cin >> str;
while(str!="exit"){
char test[512];
strcpy(test, str.c_str());
expression exp(test);
// cout << pow(4.0f,5.0f);
cout << "\n" << str << " = " << exp.value() << "\nif this is not corect, please tell me and provide the expression you entered\n\nenter another expression or type exit to do so:\n";
str = "";
cin >> str;
}
cout << "thank you for testing me";
}

Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Anaz

  • 210
absolutely critical that you play with this small stand alone app
it is actually a "feature" of cin. cin leaves whatever comes after whitespace in the input stream without removing it. use cin.getline() instead if you want to avoid that particular feature.
Arrr. I'm a pirate.

AotD, DatDB, TVWP, LM. Ph34r.

You WILL go to warpstorm...

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
absolutely critical that you play with this small stand alone app
This is one reason why I never use cin, cout, or filestreams. :p
-C

 

Offline Drew

  • 29
    • http://www.galactic-quest.com
absolutely critical that you play with this small stand alone app
1-2*2 = -3
wrong
[(WWF - steroids + ties - spandex) / Atomic Piledrivers] - viewing audience = C-SPAN

My god.. He emptied the gasoline tank from the van onto your cat, lit him on fire, threw him in the house and dove for cover.  :wtf: Family indeed.  ~ KT

Happiness is belt fed.

 

Offline StratComm

  • The POFressor
  • 212
  • Cameron Crazy
    • http://www.geocities.com/cek_83/index.html
absolutely critical that you play with this small stand alone app
Actually Drew that's right.  1-4 is -3.
who needs a signature? ;)
It's not much of an excuse for a website, but my stuff can be found here

"Holding the last thread on a page comes with an inherent danger, especially when you are edit-happy with your posts.  For you can easily continue editing in points without ever noticing that someone else could have refuted them." ~Me, on my posting behavior

Last edited by StratComm on 08-23-2027 at 08:34 PM

 

Offline Carl

  • Render artist
  • 211
    • http://www.3dap.com/hlp/
absolutely critical that you play with this small stand alone app
Multiplication comes before subtraction in orders of operation, Drew.
"Gunnery control, fry that ****er!" - nuclear1

 
absolutely critical that you play with this small stand alone app
Bobb: What about doing what the TI calculators do and use a different minus sign for the negative and the substraction? Use an underscore or something for one of them.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline Drew

  • 29
    • http://www.galactic-quest.com
absolutely critical that you play with this small stand alone app
Quote
Originally posted by StratComm
Actually Drew that's right.  1-4 is -3.


not when you work the operations seperate.  whatever.
[(WWF - steroids + ties - spandex) / Atomic Piledrivers] - viewing audience = C-SPAN

My god.. He emptied the gasoline tank from the van onto your cat, lit him on fire, threw him in the house and dove for cover.  :wtf: Family indeed.  ~ KT

Happiness is belt fed.

 

Offline Scuddie

  • gb2/b/
  • 28
  • I will never leave.
absolutely critical that you play with this small stand alone app
WMC, I hope you don't mind me using your example :p.

-(2^-(3)+1)-3=10 FALSE
-1*(2^(-3)+1)-3=4.125 TRUE

It's all in the way you write the equation.  In basic, low level mathematics, the first statement is invalid.  Understood elements cannot be parsed, because the program doesn't know what understood element it is.  Therefore, direct logical equations must be used.

EDIT:  If I may ask, why are we playing with this calculator?  What is it for?
« Last Edit: April 28, 2005, 10:45:20 am by 739 »
Bunny stole my signature :(.

Sorry boobies.