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

Oliver 2015582 at bugs.launchpad.net
Fri Apr 7 16:16:56 UTC 2023


Public bug reported:

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.

** Affects: bc (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to bc in Ubuntu.
https://bugs.launchpad.net/bugs/2015582

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

Status in bc package in Ubuntu:
  New

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 manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bc/+bug/2015582/+subscriptions




More information about the foundations-bugs mailing list