Page MenuHomeFreeBSD

dc(1): fix input of non-decimal fractional numbers
ClosedPublic

Authored by asomers on Dec 2 2017, 6:59 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Mar 27, 4:00 PM
Unknown Object (File)
Wed, Mar 27, 4:00 PM
Unknown Object (File)
Jan 16 2024, 3:17 PM
Unknown Object (File)
Dec 20 2023, 4:00 AM
Unknown Object (File)
Sep 8 2023, 5:38 AM
Unknown Object (File)
Jul 15 2023, 4:33 PM
Unknown Object (File)
Jul 4 2023, 11:40 AM
Unknown Object (File)
Jul 4 2023, 11:38 AM
Subscribers

Details

Summary

dc(1): fix input of non-decimal fractional numbers

Inputting fractional non-decimal numbers has never worked correctly in our
OpenBSD-derived dc(1). It truncates the number to a number of decimal places
equal to the number of hexadecimal (or whatever base) places given on the
input. That's unacceptable, because many numbers require more precision to represent in base 10 than in their original bases.

Fix this bug by using as many decimal places as needed to represent the input,
up to the maximum of the global scale factor.

This has one mildly surprising side effect: the scale of a number entered in
non-decimal mode will no longer equal the number of hexadecimal (or whatever
base) places given on the input. I think that's an acceptable behavior change,
given that inputting fractional non-decimal numbers never worked in the first
place, and the man page doesn't specify whether trailing zeros on the input
should affect a number's scale.

PR: 206230

Test Plan

Kyua tests added

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

usr.bin/dc/tests/inout.sh
1 ↗(On Diff #36095)

After adding the shebang, please also add the SPDX ID license identifier.

This revision is now accepted and ready to land.Dec 2 2017, 3:51 PM
This revision was automatically updated to reflect the committed changes.