Summary: | dc(1) bugs | ||
---|---|---|---|
Product: | Base System | Reporter: | nibbana |
Component: | bin | Assignee: | Alan Somers <asomers> |
Status: | Closed FIXED | ||
Severity: | Affects Some People | CC: | asomers |
Priority: | --- | ||
Version: | 9.3-RELEASE | ||
Hardware: | i386 | ||
OS: | Any |
Description
nibbana
2016-01-14 09:09:37 UTC
The problem is simpler than you suggest. It looks like fractional input doesn't work correctly when the input base is 16. Try this: $ dc -xe 16i0.1p 0.0 $ dc -xe 16i0.8p .5 $ dc -xe 16i0.4p .2 The first and third results are wrong, and the second result is correct. I get the same results with both the FreeBSD and the GNU versions of both bc(1) and dc(1). I suspect the problem is that some number is being treated as an integer in units of base^n for n < 0 _before_ conversion to a bignum. That would explain these three results, for n=-1. FWIW, OpenBSD has recently documented the bug: https://github.com/openbsd/src/commit/07a84ed5d032f8944e094f78671ca22370d85d94#diff-5b6538785ff0a1cae35f0be94d4853ce A commit references this bug: Author: asomers Date: Tue Dec 5 04:22:36 UTC 2017 New revision: 326556 URL: https://svnweb.freebsd.org/changeset/base/326556 Log: 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 input 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 r10 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 necessarily 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 Reported by: nibbana@gmx.us Reviewed by: pfg Differential Revision: https://reviews.freebsd.org/D13336 Changes: head/etc/mtree/BSD.tests.dist head/usr.bin/dc/Makefile head/usr.bin/dc/bcode.c head/usr.bin/dc/bcode.h head/usr.bin/dc/extern.h head/usr.bin/dc/inout.c head/usr.bin/dc/mem.c head/usr.bin/dc/tests/ head/usr.bin/dc/tests/Makefile head/usr.bin/dc/tests/inout.sh |