Parens
I'm a little let down this morning. I learned somewhere in college (probably from a classmate) that the singular of parentheses was paren. Certainly a lot easier to say, anyway. But when I looked it up in the dictionary this morning…
pa·ren·the·sis |pəˈrɛnθɪsɪs|
noun ( pl. -ses |-siːz|)
…
- (usu. parentheses) one or both of a pair of marks ( ) used to include such a word, clause, or sentence.
The singular is parenthesis, and it all but condones using the plural for a single mark. But all is not lost!
paren |pəˈrɛn|
noun (usu. parens) Printing
a parenthesis.ORIGIN early 20th cent.: abbreviation of parenthesis.
I don't know about you, but I'm sick and tired of saying parentheses (we say that a lot in programming). I propose that we usher in the shift from parentheses to parens. In programming, at least, let's use the word paren for singular and parens for plural. Will you join me?
P.S. The British tend to call parens "brackets," which is short for "round brackets." I was teaching a class on C and had a British student, and I had her totally confused because to me "brackets" meant square brackets. When I said brackets (meaning square brackets) she thought parens. When she said brackets (meaning round brackets by default) I thought square brackets. When I said braces I meant curly braces (what other kind are there on the keyboard?), but to her braces was a synonym for brackets…
Convergent Rounding
The rounding they taught you in elementary school has an eventual bias. i.e.
over time you find that you've rounded up more often than you've rounded down.
Bias is a bad thing, especially in DSP and other numerically-intensive computing.
Convergent rounding is one good way to eliminate this bias. It works the same
as regular rounding except that instead of rounding 0.5 up, you round 0.5 to
the nearest even number. So 1.5 goes to 2.0, 2.5 goes to 2.0, etc.
A quick tutorial on short fixed-point programming in C. The decimal point is
between bits 15 and 14, and bit 15 is your sign bit. So, you have a range of
1-2^-15 to -1. So 0.5 is 0x4000, and -0.5 is 0xC000 (two's complement). Now,
when you multiply two numbers together you get twice as many bits of precision,
so multiplying two shorts gives you an int, and in that int the decimal point
is between bits 30 and 29, and bits 30 and 31 are sign bits. We want to round
at bit 15 so we can fit the result back into a short. Clear as mud?
The point of this post is to get this C code out there, because as simple as it
seems it was a devil to debug:
int cround(int a)
{
if (a & 0x3fff)
a += 0x4000; // normal rounding
else
a += (a>>1) & 0x4000; // convergent rounding
return a & 0xffff8000;
}
If you don't see why this works (I didn't when I first read the "add half of
the lsb uf the upper part" algorithm), then fill out this truth table as an
excercise:
0.00
0.01
0.10
0.11
1.00
1.01
1.10
1.11
Here's an example of the function in use:
short x,y;
int a;
x = 0x7ffd; // x = almost 1
y = 0x4000; // y = 1/2
a = x*y; // a = 0x1fff4000
a = cround(a); // a = 0x1fff0000
x = a>>15; // x = 0x3ffe