gavinhoward / bc

An implementation of the POSIX bc calculator with GNU extensions and dc, moved away from GitHub. Finished, but well-maintained.
https://git.gavinhoward.com/gavin/bc
Other
162 stars 32 forks source link

Fixed printing error. #74

Closed naggamura closed 9 months ago

naggamura commented 9 months ago

Found a printing error. Try obase=2; 2^99; 2^100; 2^105; you'll get it right away.

gavinhoward commented 9 months ago

You are correct; that is a bug.

Your fix is correct; I got the condition backwards. Accepted without comment.

Sorry for taking so long, I struggle to read my own code; this is why I put in so many "useless" comments!

Also, I can think of another place that this could have been a problem and quickly tested it.

The problem is in printing in bases above base 16, where multiple characters may be printed for one digit.

Guess what? I tested your fix after accepting it (I wanted your name in the Contributors list regardless), and your fix works for that too!

Try this:

$ BC_LINE_LENGTH=77 bc
>>> obase=128
>>> 2^126
 001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
>>> quit

That's what it is with the fix. Without, the bug shows:

$ BC_LINE_LENGTH=77 bc
>>> obase=128
>>> 2^126
 001 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 00\
0
>>> quit

I checked your fix with BC_LINE_LENGTH=78 and BC_LINE_LENGTH=76, and your fix properly handles both.

I am confident in your fix.

Anyway, I'll start my release process and put out a release with your fix ASAP.

naggamura commented 9 months ago

Oh I helped... ^^; I'm happy. I'm Jonathan Kim

gavinhoward commented 9 months ago

Yes, you did! And your fix has now passed the release process untouched.

Please don't think I'm a jerk for your previous PR; I try to not be.

I just have ridiculously high standards and personal weaknesses in programming. And an eccentric style.

In fact, I don't accept contributions at all in my next project. Nothing against people, but I really struggle with patches. It's so bad that I actually can't get a programming job because of that. If you work in the industry, you're doing better than me.

And nice to meet you. :)