racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
448 stars 95 forks source link

In BSL number->string produces improper fraction when should produce decimal #339

Closed jamie255 closed 4 years ago

jamie255 commented 4 years ago

In DrRacket 7.5 in vanilla Beginning Student, the following gives a decimal answer:

(/ (round (* 10000 (/ 48 147))) 100))

But (number->string (/ (round (* 10000 (/ 48 147))) 100))) produces "653/20"

jbclements commented 4 years ago

I ... don't think that's a bug. the result of the numerical operation is an exact number, a fraction. It's displayed in the beginner language interactions window as a decimal, but if you try (/ 1 3) you'll see a bar over the three; I think you really wouldn't want a "number->string" that produced numbers with bars over them.

Maybe I should say: what behavior would you expect to see, here?

jbclements commented 4 years ago

BTW, if this is the Jamie Raymond that used to have a desk next to mine at Northeastern... hi!

jamie255 commented 4 years ago

Sure, I can see that it might not be a bug, but the behavior is unexpected. I would expect the string to be the same as the displayed number. My students would certainly be confused by this [i.e. that they don't display the same].

Edit: [strike-through I've found a workaround: by dividing by 100.0 instead of 100, the string will contain the decimal variant instead of the fraction. Still confusing for the students, though.]

Edit: Darn. Tested the above (cf. 100.0) in #lang racket rather than BSL. BSL still shows the improper fraction in the string.

On Sun, Jan 26, 2020 at 7:56 PM John Clements notifications@github.com wrote:

I ... don't think that's a bug. the result of the numerical operation is an exact number, a fraction. It's displayed in the beginner language interactions window as a decimal, but if you try (/ 1 3) you'll see a bar over the three; I think you really wouldn't want a "number->string" that produced numbers with bars over them.

Maybe I should say: what behavior would you expect to see, here?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/racket/drracket/issues/339?email_source=notifications&email_token=AABXDMLTPUDMCX6EJ2EECB3Q7Y5OJA5CNFSM4KL2RGNKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ6EEII#issuecomment-578568737, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXDMI5VC3PK3OBFU4QOXDQ7Y5OJANCNFSM4KL2RGNA .

mfelleisen commented 4 years ago

DrRacket has many display options for numbers. If you right click (for some value on right) on the number, you can change the rendering of a number in DrRacket. So what you see in the Interactions Window is not the rendering of a number. ~~ I think this is a good teaching moment.

Remember that you can also use #i (inexact) and #e (exact) for numbers. At some point this was early in HtDP because computer numbers are not mathematical numbers and as much as try to hide the issue in BSL, we can't complete hide it.

jamie255 commented 4 years ago

Thanks Matthias. I understand the underlying issue, although I was hoping to avoid the 'representation of numbers' discussion this early in the semester. I'm going to close this issue.