The temperature is right around 0° F (-18° C) and it's time to go swimming. So here I am ready to walk to the pool.

I ran into this scenario a several years ago on the job. This is C99 code, but it will not compile.

int value;

// ...

switch ( value )

{

case 1:

int accumulator = 1;

break;

case 2:

int accumulator = 2;

break;

}

// ...

switch ( value )

{

case 1:

int accumulator = 1;

break;

case 2:

int accumulator = 2;

break;

}

It is a good practice to define and use variables as close to where they are needed and limit their scope as much as possible. My understanding is that this helps the compiler as registers optimization is easier if the life span of a variable is clearly define.

Why this code won't compile has to do with scope. A case statement will not create a private area of scope.

Adding redundant braces fixes this problem:int value;

// ...

switch ( value )

{

case 1:

{

int accumulator = 1;

break;

}

case 2:

{

int accumulator = 2;

break;

}

}

// ...

switch ( value )

{

case 1:

{

int accumulator = 1;

break;

}

case 2:

{

int accumulator = 2;

break;

}

}

What is happening here is that the variable *accumulator* in the first example is within the scope of the switch statement, where as with the second example, *accumulator* scope is limited to the case. The *case*/*break* statement does not define a block of scope.

I always use the redundant braces around case statements. However, when I discovered this problem, I was working for a company that didn't like the redundant braces and told me not to use them. While it was often difficult for me to abandon what I considered good coding practices, it was useful in finding "gotchas" caused by not-as-good practices. Various companies I have worked for have different policies on coding standards. Some were really good, but most were either non-existent or poor to the point of being useless. While developing coding standards can become a religious war I think it is more useful to have a good standard than no standard at all. This is especially useful for new programmers who generally have no common practices and could easily stumble on a problem like this.

Interesting example of variable scope! If so much of it is poor, why do companies even bother with coding standards?

A few days ago I added support for doing three linearizable functions to my online polynomial regression calculator. Today I finished adding support for weighting terms. This provides the ability to unequally weight data going into the regression calculation.

Pictured is Desirae playing the part of the dead (but adorable) Little Blond Dame checking the door for those party-pooping lawmen. She took a few rounds on St. Valentine's Day a few years back, but comes to visit when it is Friday the 13^{th}.

Pictured is Desirae playing the part of the dead (but adorable) Little Blond Dame checking the door for those party-pooping lawmen. She took a few rounds on St. Valentine's Day a few years back, but comes to visit when it is Friday the 13

Usually when I fail to accomplish some task I don't bother to write about it. However I think it might be interesting to write about some of my failed approaches to problems. Today I was looking into implementing a function to calculate the inverse sine function (arcsin) to arbitrary precision. I've done this in the past for log, exponential, sine, cosine, and pi. Right now, however, I have no inverse trigonometric functions.

The easiest way to implement any continuous function is to use it's Maclaurin series (the Taylor series centered at zero). This is easy to find for most functions, and here is the series for inverse sine:

This series suffers from a problem that many series do—it converges slowly when *x* is near 1 or -1. I typically address this by using the Taylor series with some different points to solve the problem. The first natural choice here is 1 and -1 since these are problem points. In order to calculate the Taylor series we need a general equation for the n^{th} derivative. After some searching around I found this equation:

That's a mess, but we can now apply the Taylor series to this. Recall the Taylor series expansion for a function:

So we want to take the n^{th} derivative for 1 and -1. However, it quickly becomes apparent that something bad is going to happen if we do this.

Reduce:

And that's a problem—one cannot divide by 0. Using -1 is no better because squaring negative one is just one, and results in the exact same problem.

Here my approach simply cannot be applied, and I will have to look into other methods to address the issue of slow converges. I have not taken any formal numerical analysis and lack the an understanding of the tools one would typically use to tackle this kind of problem. However that hasn't stopped me in the past. So I will need to think on it more.

Attended a physics demonstration today with Pokie, Mike, Mira, and Mallory. It was mainly for kids, but I thought it was great. The demonstrations were all fun science and the kind of thing I use to love when I was younger. I hope it inspires some of those kids in the audience to pursue a study of science.

Tonight the 1920s gangsters took on 1980s horror in a Friday the 13^{th} St. Valentine's Day Massacre. Pictured are Vinny, Sal, a camp counselor, Vito, and the dead Little Blond Dame.

Today I finished the changes to the PHP Polynomial Regression Class and released version 1.2. I've added two new fetchers. First is weighted regression. The second is the addition of linearized regression functions. The linearized regression functions where added February 8th, 2015 as I wrote about their addition to the online calculator. Both sets of functions were implemented quickly and the longest part was cleanup and documentation needed before release.

My polynomial regression site is the most popular site on DrQue.net, just slightly ahead of the King's Quest Walkthrough. As such I thought I'd use some downtime I have at work to add to the library. There are some more fetchers I plan to add, but this is a good starting point.

My polynomial regression site is the most popular site on DrQue.net, just slightly ahead of the King's Quest Walkthrough. As such I thought I'd use some downtime I have at work to add to the library. There are some more fetchers I plan to add, but this is a good starting point.

My collection of hookup wire. It is pretty meager compared to the electrical labs I've worked, but I have enough to get my small projects running.