GNU bc should warn the user if he enters a digit that doesn't exist in the defined input base (binary, octal, decimal, hex)

Bug #2015582 reported by Oliver
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bc (Ubuntu)
New
Undecided
Unassigned

Bug Description

With GNU BC you can define with ibase and obase which base system should be used for input (ibase) and output (obase)

I you run GNU BC and enter:
ibase = 2

GNU bc will switch to binary input and interpret every number that is made of the digits 0 or 1 as binary number.

Example:
The entry of:
10 + 1
will give the decimal result of:
3
This is correct, because 10 is a binary number and thus equals the decimal value of 2. And 2+1 = 3

But when you enter:
9 + 1
GNU bc will output:
10
In the decimal system the output is correct, 9+1 is 10, but it shouldn't be allowed to enter a 9, when the base system chosen for input is binary.
It just confuses the user.

A typical output of GNU bc with ibase set to 2 (binary) and obase set to A (decimal).
1+1
2
2+1
3
..
..
8+1
9
9+1
10
10+1
3
You see, while the output is correct, this is still very confusing and could lead to errors.
Outputting a warning that 2, ..., 8 and 9 are not a binary digit would be the minimum.

It can even get worse, the user might enter something like (For this bc has to be started with the parameter -l):
ibase=2
10*10^-3
.2500000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000

But it wasn't what he really wanted. He had forgotten, that the exponent has also be given in binary form. Actually he wanted to enter 10*1010^11.
10*1010^-11
.0020000000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000

Because 1010 a binary number is 10 in decimal.
A binary 10 is not 10 in decimal, it is 2. And the allowing of the none binary digit -3 confuses him and leads to manual errors when inputting data.

Summary:
It shouldn't be allowed, that the user can enter digits that do not exist in the selected
base system for input. At least a warning should be given, when he does so.

If ibase=2 (binary system) is entered then only the digits 0 and 1 should be allowed.
If ibase=8 (octal system) is entered then only the digits 0, 1, 2, 3, 4, 5, 6, 7 should be allowed.
If ibase=A (decimal system) is entered then only the digts 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 should be allowed.
If ibase=G (Hex system) is entered then only the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F should be allowed.

All other digits should output at least a warning.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.