Bug 162495

Summary: dc(1): dc -e "5 3 %p 1k 5 3 %p"
Product: Base System Reporter: John Smith <dcbug12345>
Component: binAssignee: Alan Somers <asomers>
Status: Closed FIXED    
Severity: Affects Only Me CC: asomers
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description John Smith 2011-11-11 22:10:05 UTC
/usr/src/usr.bin/dc/

%dc -e "5 3 %p 1k 5 3 %p"
2
.2

Output of the modulo operator is divided by 10(scale) when scale>0.

From what I tested the bug doesn't appear to happen in bcode.c:bmod(void), it looks like it happens some time after it is called.

How-To-Repeat: %dc -e "5 3 %p 1k 5 3 %p"
2
.2
Comment 1 commit-hook freebsd_committer freebsd_triage 2017-12-07 02:09:03 UTC
A commit references this bug:

Author: asomers
Date: Thu Dec  7 02:08:56 UTC 2017
New revision: 326652
URL: https://svnweb.freebsd.org/changeset/base/326652

Log:
  dc(1): fix modulo operations with fractional inputs

  Our dc(1) has never correctly calculated remainders with fractional inputs.
  Both bmod and bdivmod seem to have copy/pasted code from bdiv, which results
  in the remainder having the wrong output scale.

  PR:		162495
  Reported by:	anonymous
  Reviewed by:	pfg
  Differential Revision:	https://reviews.freebsd.org/D13390

Changes:
  head/usr.bin/dc/bcode.c
  head/usr.bin/dc/dc.1
  head/usr.bin/dc/tests/Makefile
  head/usr.bin/dc/tests/bcode.sh
  head/usr.bin/dc/tests/inout.sh