8000 Display numbers in hex, binary, etc · Issue #5 · soudy/mathcat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Display numbers in hex, binary, etc #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tv42 opened this issue May 19, 2016 · 3 comments
Open

Display numbers in hex, binary, etc #5

tv42 opened this issue May 19, 2016 · 3 comments

Comments

@tv42
Copy link
tv42 commented May 19, 2016

Hi. Nice project, love the programmer-friendly bit manipulation. However, this was a little disappointing:

mathcat> 0b1101001 << 1
210

I wish I could get the result out in bits/hex/etc.

@soudy
Copy link
Owner
soudy commented May 19, 2016

Hi, thanks for the feedback.
I like this idea, perhaps add a command like @mode <mode> where is decimal, hex or binary. It would be difficult and perhaps undesireable to automatically return the result in for example binary if binary happens to be used in the expression.

@tv42
Copy link
Author
tv42 commented May 19, 2016

Yeah. Though I can't help but wonder what would happen if one treats the output format of a number a "sticky" property as values are passed through computation, with combining rules in the spirit of Go's untyped constants.

mathcat> 0b1
0b1
mathcat> 0b1 + 1    ("untyped" 1)
0b10

Then have rules that say which one wins in case of multiple conflicting ones; e.g.

mathcat> 0b1 + 0d1
2  (decimal wins)
mathcat> 0b1 + 0d1
0b10  (left one wins)
mathcat> 0b1 + 0d1
2  (right one wins)

(Instead of my invented 0d42 decimal literal format, you could also do just dec(42))

Right one wins has the nice property that you can often arrow-up, +0b0, enter to change the format. Kinda like how some dynamic languages do data types. Not sure if that's a good idea ;)

Probably something like dec(_) is nicer, "format the last value as decimal".

@soudy
Copy link
Owner
soudy commented May 19, 2016

That would be ideal, but tough to implement as the parser has no concept of hex, binary or decimal, everything is a float in the end. I'm sure it's doable though. For example by lexing it first and checking the most common type of literal, since the lexer is aware of the type literal.

I'll have to look into this some more, if you have any ideas I'd be glad to hear them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0