Skip to content
Sign upLog in
← Back to Community

An actual good calculator

Profile icon
FlaminHotValdez

There are like a BAJILLION posts on replit that are "calculators" that go like this:

Please input which operation you would like: Plus, minus, add, or divide

Please input which numbers you would like to add.

I got bored of those, and I made a calculator where you can just straight up input the expression you want to calculate. Works with +,-,*,/,^ for exponent, and parentheses! Not only that it follows order of operations too. It even has decimal capability of 10 places. Also, no eval() function.

The purpose of this post? To make a calculator where you can just enter your math expression instead of printing "Plus, minus, multiply or divide?" without using eval. also to prove that stacks are useful because basically no posts on replit use stacks

EDIT: Y'all are razzing on me because my calculator doesn't work for super big numbers or if you just input gibberish. But seriously there is a thing called integer limit... sigh

UPDATE: Floor division has been added.

Voters
Profile icon
AnaghRaina
Profile icon
hydynn
Profile icon
SelenaYang1
Profile icon
XanthusPettitt
Profile icon
Baconman321
Profile icon
Whippingdot
Profile icon
forceofyoda
Profile icon
Brendan23
Profile icon
tussiez
Profile icon
KobeFF
Comments
hotnewtop
Profile icon
SilvermoonCat

185D07C5-1CF4-4075-9135-9BEBAF8B8A10


hmph, for one other test it returned “inf”

Profile icon
FlaminHotValdez

@SilvermoonCat
Do you not know of a thing called integer limit?

Profile icon
SilvermoonCat

@FlaminHotValdez
ofc I do I was just trying some "things'

Profile icon
Coder100

image


ah, yes, math

Profile icon
FlaminHotValdez

@Coder100
It doesn't work with equations, only + - * / ^ ()

Profile icon
angrydoge
Profile icon
tussiez
Profile icon
FlaminHotValdez

@tussiez
sigh, yall are razzing on me for having "bad math" but no other calculator on replit can handle big numbers, equations, and random letters. At least my calculator allows you to straight up enter an expression and it follows pemdas instead of other basic calculators that can literally do one operation.

Profile icon
tussiez
Profile icon
FlaminHotValdez

@tussiez
html eval? Sigh. Seriously the whole point of this post was to not use eval and have a straight-up expression input instead of "Would you like to add, subtract, multiply or divide?"

Profile icon
tussiez

@FlaminHotValdez
HTML JS
Yee, that's what I like about this post, and why it has my upvote

Profile icon
FlaminHotValdez

@tussiez
...Yes js eval much better lol...Glad u like it tho, but yeah the whole point of this post is to have a calculator where you can just enter your expression instead of printing "Plus, minus, multiply or divide?" without eval and similar functions.

Profile icon
tussiez
Profile icon
Coder100

wait looking at your code it's more of a regular lang than a context-free lang. what's going on here

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100
? Wdym?

Profile icon
Coder100

it doesn't fully recurse

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100
it's...not a recursion-based thing, it's a stack

Profile icon
Coder100

for example, you don't really care if the equation is valid, and thus you can easily have it segfault

@FlaminHotValdez

Profile icon
Coder100

the thing is a context-free language, which math is, recurses so to have precedence

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100
yeah IK lol, but I wasn't trying to make it perfect, the goal of this was just to make a calculator where you could just enter the expression instead of choosing what operation then entering the integers. Also no eval.

Profile icon
FlaminHotValdez

@Coder100
I do have precedence, the code is super complicated but trust me it works

Profile icon
jihhyuu202

you can use strings to store the number [email protected]

Profile icon
FlaminHotValdez

@jihhyuu202
wdym? I am using a string but my method of calculation relies on stack

Profile icon
Coder100

strings won't work because you can't do calculations with them

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100
ik that's what I said: my method of calculation depends on stack

and what are you doing here?

Profile icon
Coder100

i got the ping

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Coder100
oh

so you respond to pings?

Profile icon
henryeth

Me: makes good calculator.
After that.
Valdez: makes similarly good calculator.
Me: gets 3 upvotes.
Valdez: gets 15+ upvotes and a ton of recognition.
How I love repl.it.

Profile icon
FlaminHotValdez

@henryeth
Not my fault! cowers behind wall

Profile icon
FlaminHotValdez

@henryeth
also if you haven't noticed everybody's shaming on my calculator lol

Profile icon
henryeth

@FlaminHotValdez
yh I am sure it would be the same for me tbh. I know it isn't your fault. It is in a different language (maybe that is the reason???) so it obviously isn't any kind of a copy (the one thing I would be especially angry if it was).

Profile icon
FlaminHotValdez

@henryeth
lol...no offense but this repl was created and coded about 10 months ago, recently I added a bit and debugged it you can look at the history.

Profile icon
henryeth

@FlaminHotValdez
really wow, no offense taken

Profile icon
henryeth

@FlaminHotValdez
haha yes now I have winning calculator again :evil laugh: check my new post.

Profile icon
FlaminHotValdez

@henryeth
ah rip

Profile icon
MaxFromYT

9^-98765 dumped it

Profile icon
DaCuteRaccoon

image

LOL I just caused a core dump by declaring a variable x = 2 (without the type specification like int, long long int, float, etc.) and then return x to the power of x (2**2). You should really add algebraic expressions :)

Profile icon
FlaminHotValdez

@DaCuteRaccoon
easier said than done

Profile icon
DaCuteRaccoon

You can use things like long long int. Or you could not use cpp to make it.

Profile icon
FlaminHotValdez

@DaCuteRaccoon
Yeah, but that's memory murder

Profile icon
DynamicSquid

Hi, this is really random but do you do competitive programming? I think I saw it in a comment somewhere

Profile icon
FlaminHotValdez

@DynamicSquid
Yeah! I do! In fact, this post was actually originally one of the problems I did for practice

Profile icon
DynamicSquid

@FlaminHotValdez
Nice! I do too (although not good at it) Which website do you use?

Profile icon
FlaminHotValdez

@DynamicSquid
I participate in the USACO contests(And I'm terrible. Welcome to the club). I'm enrolled in a coding class, and they also have a website full of coding problems. Also I think we had this "competitive programming" thread somewhere else...I lost it though lol

Profile icon
DynamicSquid

@FlaminHotValdez
Cool! Planning to join the USA coding olympiad?

Profile icon
FlaminHotValdez

@DynamicSquid
Already participating

And failing hard

Yippee!

WBU? I think you're in Canada or something?

Profile icon
DynamicSquid

@FlaminHotValdez
Yeah, I'm in Canada. First we have the Canadian Computing Competition (CCC). Each year there's about 7000 participants. If you get around top 20, then you're invited to the Canadian Computing Olympiad (CCO). The top 4 from the CCO go to the International Olympiad of Informatics (IOI) 👀.

Last year I was like bottom 6000 in Canada lol. But this year I was top 731. And next year, which will be my last year, I'm really hoping to be top 20 to get into the CCO 🙏

Profile icon
FlaminHotValdez

@DynamicSquid
Cool! In the USA, we have the USACO(United States of America Computing Olympiad), which is split into 4 tiers. Bronze, silver, gold, and platinum. You start out at bronze. When you take the contest, you take the contest respective to your tier, and if you do well(Usually 75%), you advance to the next tier. The USACO contests are held four times a year. Once in December, once in January, and once in February. Then there's the one called the "US Open." It usually takes place in March, but this year it happened in early April. The questions on the US Open are harder than the other contests, and the top 20-ish scorers from Platinum in the US Open advance to a "camp" of sorts. Then, the top 4 in the "camp" are chosen to go to the IOI. Last year in February, I advanced from bronze to silver. And I've been stuck on the silver for 5 contests straight. They say it's the biggest jump between levels.

EDIT: If you read through that entire paragraph I apologize on behalf of your eyes.

Profile icon
DynamicSquid

@FlaminHotValdez
Interesting! I think America has won 3 consecutive gold medals at the IOI so far, so you guys are doing way better than us! Well, good luck for the December contest :)

Profile icon
FlaminHotValdez

@DynamicSquid

Thanks! Good luck to you too! And yeah...USA has won 3 consecutive gold medals in the past 3 years. But I think the tides will turn...

benjamin qi is gone from the team mwahahahahahahahah

sadly he still writes problems
Profile icon
Whippingdot

I live in India, so is there any way I can try qualifying in the IOI? The only website I found looked very ummm bad. The IOI website didn't help me as it didn't talk about the countries that participate

@FlaminHotValdez

Profile icon
Whippingdot

Also, I have to live in USA to do that USACO thing right? I can't do it even though I was born there?

@FlaminHotValdez

Profile icon
FlaminHotValdez

@Whippingdot
No, USACO is open for everyone, but only US citizens that are not yet college age can qualify for IOI. I'm not sure whether India is in ioi tho :(

Profile icon
XanthusPettitt

how does python stacks work?

Profile icon
FlaminHotValdez

@XanthusPettitt
I'm actually not sure if Python has an innate stack.

Profile icon
XanthusPettitt

@FlaminHotValdez
oh... well then ok lol

Profile icon
XanthusPettitt

hey,

@flamingHotValdez
, I'm making a calc of my own could you take a look at it? its not finished but I feel like it could use some tuning

Profile icon
Kudos

I'm not insulting your calculator I'm just meme-ing chill

image

image

If x = 72 then 2x = 92 😁 I luv math

Profile icon
FlaminHotValdez

@Kudos
ascii, the ascii for x = 72

Profile icon
btfuss