RealRTTV / chatcalc

a port of chatcalc to 1.19-1.20
Mozilla Public License 2.0
11 stars 5 forks source link

Base Conversion? #13

Closed noahyor closed 7 months ago

noahyor commented 8 months ago

I think it might be nice to be able to convert to and from binary and/or other bases within this mod without doing tedious manual conversion. Thank you for your work on this mod!

RealRTTV commented 8 months ago

how would this work though? can you provide example syntax, thanks

noahyor commented 8 months ago

-> b would convert to binary? or -b>?

noahyor commented 8 months ago

Could work by repeatedly using left bit shift 1 modulo 2. I think you shouldn't allow it to convert non-integer values.

RealRTTV commented 8 months ago

its already spec to use 0b... for binary, and 0x... for hex, i can encode constants that way, but for outputting ones, i honestly don't have a clue, i could change the base in the output

noahyor commented 8 months ago

you could write 0d3 -b> and it would output 0b11, for example

noahyor commented 8 months ago

I think i might like to try to implement this on a local branch.

noahyor commented 8 months ago

I see the problem with printing the converted string now. I think I might be able to do it with some major refactoring. As a side note, I fixed the crash that happened when an invalid decimal format string was used. In the case of an invalid string, it reverts to the default for the remainder of that session.

RealRTTV commented 8 months ago

you could write 0d3 -b> and it would output 0b11, for example

chatcalc does not support spaces in expressions i can always make my own decimal formatter and allow it to have custom bases

RealRTTV commented 8 months ago

smth like rust: .2 for (1.234 -> 1.23) ,.2 for (1024.32 -> 1,024.32) 04,.2 for (4.1 -> 0004.10) .<2 for (4.133 -> 4.13 or 4.1 -> 4.1) 00.<2 for (1.2 -> 1.2 or 0.2 -> .2) #01.<2 for (10 -> A or 10.4 -> A.67) (the 01 is inferred and can be omitted) b.0 for (3 -> 10 or 127 -> 1111111) (the .0 is inferred and can be omitted) hows that look?

noahyor commented 8 months ago

I don't understand that format. Could you please re-explain?

RealRTTV commented 8 months ago

a comma adds commas a . then a number specifies the amount of decimals to put in a 0 then a number says the minimum amount of digits in the int part, ex: 01 is the default so 0.2 becomes 0.2 but if it were 02 then 0.2 would be 00.2, or 00 would have no prefixing int parts at a minimum, meaning .2 is the result a # makes the number hex, a b makes the number binary adding a < between the . and the int (for the number of decimal places) makes it go up to that, that way 1.2 doesn't map to 1.20 unnessesarily

noahyor commented 8 months ago

I like that, thanks for the explanation!

RealRTTV commented 8 months ago

hi so, ok, idk how to say this, but this is difficult, like crazy difficult, I could totally work on this but it would take a week to do and that's time I don't have right now, I can totally add 0b111 constants and 0xFF constants, but if I'm adding custom base printouts, that's incredibly difficult with my current time. because of this, I'm likely unable to add this feature, I hope you understand.

noahyor commented 7 months ago

That is fine. I think I might like to do this on my own time. If I somehow get it to work I can give you the code.

RealRTTV commented 7 months ago

the challenge is getting it to work with floats, not just integers

noahyor commented 7 months ago

How would the floats theoretically work?

RealRTTV commented 7 months ago

well in my dev version, constants already exist like 0b11.11 for 3.75, or 0xFF.FF for 255.99609375

RealRTTV commented 7 months ago

so like that

noahyor commented 7 months ago

I've never really used decimal places in other bases before, but ok.

RealRTTV commented 7 months ago

good luck

noahyor commented 7 months ago

thanks.