Wednesday, January 8, 2014

Geek: Java oddity...

Geek: Java oddity...  I'm writing a replacement for Java's DecimalFormat class – faster, threadsafe, and slightly extended.  In the course of writing tests for my code, I discovered some unexpected behavior in DecimalFormat when formatting float values.  Here's some code that illustrates the behavior:

DecimalFormat df = new DecimalFormat( "#0" );
String fmt = df.format( 11111111E15f );
Run that code, and fmt will contain "11111110989762554000000" – way more significant digits than should be there.  WTF!?!

With a little bit of digging, I figured out what's going on.  The DecimalFormat class doesn't have a method with a format( float ) signature.  So what's happening is that my float parameter is being cast to a double, and the method with float( double ) signature is being called.  Inside that method, it assumes that there are 53 bits of significance in the mantissa, not the 24 actually present in the float – so it emits digits to cover all that.

I'm really surprised that was done in the first place, and even more surprised that the Java folks haven't fixed it.  That could lead to some mighty misleading results!

My class won't do that :)

WWII visualization...

WWII visualization...  This is the best one I've ever seen...

Nelson Mandela sculpture...

Nelson Mandela sculpture...  My mom sent me a photo of this sculpture, which I had never seen before.  It's located at the site where he was arrested in 1963, in KwaZulu-Natal, South Africa.  The artist is Marco Cianfanelli, a South African himself.  He's made a number of other interesting sculptures as well.

The Mandela sculpture is made from 50 steel rods, laser-cut so that the image of Mandela is visible only from one particular direction.  This site has some images that show more detail about how the sculpture was made...

Watch this...

Watch this ... and think about your relationship to your mobile phone...

The business climate in California is so bad that...

The business climate in California is so bad that ... New York looks attractive by comparison.  I tried to think of something witty to add to that, but I couldn't think of anything that topped the simple facts...

Don't underestimate the power of the Internet to make things weird...

Don't underestimate the power of the Internet to make things weird...  Seems like good advice...

Funny looking cat!

Funny looking cat!  A few months ago, I installed an oval fuzzy shelf on our north-facing living room window sill.  The intent was to provide a perch for the cats, who love to watch the hummingbirds buzzing around the feeders you can see in the background.  However, in short order Race, our border collie, decided that the shelf was perfect for him.  He couldn't care less about the hummingbirds, but he loves to perch in that window and watch for cars coming up our driveway...

Pack rat midden...

Pack rat midden...  We have several species of pack rats out here in the chaparral where we live.  Some of them build large middens, or nests, of interwoven twigs.  At right is one that we spotted near our home on a walk Debbie and I took yesterday.  I first ran into these nests about 15 years ago when I was clearing some brush on our property, and I was amazed how strong they are.  I've since read that the pack rats inside are quite well protected from predators like coyotes, who aren't strong enough or clever enough to disassemble the protective structure.  On the one in the photo, you can see one of the entrances to the nest (the dark half-moon shaped area); I found two more on other sides of it.  Altogether on our walk we saw seven of these, all within a 200 foot stretch of roadway...