3

I have this Desmos graph which is a number display. You type a button and that number gets displayed. I'm thinking about turning it into a calculator, but first I need a decimal point. (Also the negative function doesn't work, but that's a problem for another time). The way the display works is that I have a slider $a$ for the number being typed. Every subsequent digit $n$ you type, it preforms the action $a\rightarrow10a+n$.

I've tried having a separate slider "$p$" with a step of 1 to represent the place of the decimal point, but I have yet to figure out how to utilise it. The closest thing I've seen for what I'm trying to find is on this graph from a contest in $2020$, but I have absolutely no clue what the heck is going on in there.

I think it should be something along the lines of this: "after the decimal point is placed, every subsequent digit $q$ typed will be divided by [the place of the decimal point times ten] and then added onto the total", but I'm still not entirely sure how I would go about doing that.

Any ideas?

The_Animator
  • 772
  • 3
  • 23
  • 1
    Should I have to program it with a classical programming language, I would use conversion to/from string type. – Jean Marie Sep 25 '23 at 17:59
  • 2
    A personal advice : don't waste too much time building complex programs with Desmos and Geogebra which can be wonderful tools for moderate complexity issues, but soooo difficult to debug beyond a certain size ! Switch to a classical programming language... – Jean Marie Sep 25 '23 at 19:05
  • @JeanMarie I doubt that The_Animator is doing the calculator as a practical tool. My guess is that is doing it to see if he/she can do it. That's the point of several things made in desmos or more generally, in esoteric languages like Brainf*ck, Malbolge or Perl. – jjagmath Sep 25 '23 at 19:14
  • @jjagmath "doing it to see if he/she can do it" Yes, for sure, I agree, like "golf coding"... My point was just to advise a young student to switch to much more efficient/rewarding methods. – Jean Marie Sep 25 '23 at 19:25
  • @jjagmath got it spot on. There's no practical use for there to make a calculator in Desmos, I'm just doing it to test my abilities, also because I think it's kinda fun to have projects to work on! – The_Animator Sep 25 '23 at 19:36

2 Answers2

1

You can keep track on how many decimal places there are, like in this Desmos plot based on yours. What it does:

  • It introduces a new var d that keeps track on whether . was pressed (0 or 1).

  • When C is pressed, thend → 0, p → 0, and s → 1.

  • There is a new var b that is $b=s\cdot a\cdot 10^{-p}$, and the big black field now displays b (formerly a).

  • On pressing a digit, p is incremented by d.

Now when you type, say, 0.12 then b = 0.12 will hold that value, and it is displayed as such in the big black rectangle.


What I don't know how to do is when you press 0.0 which should display 0.0, but it will only start to display something other than 0 when you type a non-zero digit. To fix this, one would need strings.

emacs drives me nuts
  • 10,390
  • 2
  • 12
  • 31
0

You could set a variable PointPressed to $0$. When "." is pressed set it to $1$. Set a variable PowerOfTen equal to $1$. In the number buttons, when pressed, update a in the same way, but also if PointPressed is $1$ set PowerOfTen = PowerOfTen*10. Instead of displaying a in the output, display a/PowerOfTen

jjagmath
  • 18,214
  • Yeah, that does work from a logical perspective, but how would I make it so that PowerOfTen only changes if PointPressed is 1 in a program like Desmos? – The_Animator Sep 25 '23 at 19:11
  • I don't know if there is an if in the scripting language of desmos , but I know that there is possible to define piecewise expressions. A more mathematical way is PowerOfTen = PowerOfTen * (10^PointPressed) – jjagmath Sep 25 '23 at 19:19