Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

March, 2006

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Show Me the Money - Floating Point Numbers and Accuracy


    Floating point numbers have some accuracy problems. The reason for this is because of fractions that covert to repeating values. Most students understand that 1/3 translates to .3333333 in an infinite sequence. But not many of them know, until it bits them, that in the binary system used by computers 1/10 is a repeating fraction.


    This really shows up in comparisons. Take a look at the following code:

    For y as Double = 1 to 2 Step 0.01

    That is an infinite loop because y will never equal 2. You’ll have to use a while or do until loop and use a greater than or equal ( >= ) operator to make it work. This is the kind of thing that makes using double or floating point numbers in loops a generally bad idea.

    There have been a number of different ways that have been used to handle the round off problems caused my binary repeating fractions. Years ago Perkin-Elmer (a company better known for other things) had a computer that used a "sticky bit" to help round both up and down which resulted in much more accurate numbers. That was done in hardware floating point operations.


    While keeping track of large numbers of decimal places is important in science, in business it is all about the pennies. And pennies can be hard to track as well.


    In programming languages, DIBOL (the "B" stands for "Business") didn't support floating point numbers at all. Programmers used integers and had to keep track of where the decimal point was supposed to be. It was accurate to quite a few digits as I recall. You paid for that accuracy with performance and with requiring smarter programmers.

    COBOL had a decimal type for money operations as was mentioned. Other languages and platforms still do. The .NET Framework (and all of the languages - VB, C#, etc - that run under it) have a Decimal data type which gets special processing to not lose those pennies. For performance reasons you don't want to use them for non-money operations as a general rule.


    I used to use a change making program assignment (for x dollar amount break it down to pennies, nickels, dimes, etc) to help students see the difficulties involved in handling round-off errors. I assume that is fairly common. If you have them do it once with doubles and then let them do it again with decimals it can be an eye opener especially if you have a class discussion about why the difference.


    BTW banks still worry about lost fractions of a penny. A program manager from a large New York bank told me about a programmer who looked for transactions that resulted in fractions of a penny and rerouted those fractions to his account. Even small numbers add up if you add them billions of times. The programmer ran off with millions after a few months. I believe they did catch him though.

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    New Computer Science Education Blog at On10


    Kevin Schofield has opened up the discussion about computer science education at On10.NET with a new Education blog. His first post there asks about the kinds of information teachers and others interested in promoting CS education need to have on hand to make the case to students, guidance counselors and parents. He is particularly interested in how to get the right message to guidance counselors who seem to all too often tell students to go into anything but computer science. Jump on over and join the conversation.

    BTW I see that the CSTA blog is taking up one of my favorite causes "Computer Science for all Students?" The thoughts expressd there are quite in harmony with Kevin's statments and questions at

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    How Bill Gates Can Help Schools?


    Scott McLeod has a blog post at that asks for comments but comments do not seem to be enabled for that post so I thought I would write some of my thoughts here. The background is this opinion/editorial by Diane Ravitch in the Seattle Times. The jist of it is that Bill Gates through his foundation should fund the development of educational software and teaching tools.

    There is another investment that you could make that would be far more effective in raising student achievement than churning out another thousand or so small high schools. As the chief executive officer of the largest software company in the world, you have a certain competitive advantage. Your company really knows how to use advanced technology to teach people almost anything.

    If you took what you do best and turned it into curriculum and instruction for our schools, it would have a revolutionary effect. You could take your knowledge of software and develop amazing programs to teach mathematics, science, languages, history, literature and the arts.

    This is of course a tempting idea. It's probably not as easy as finding a cure for malaria though. There is a lot more politics involved in education for one thing.

    Short answer to the article:

    • First we need an environment that supports the use of technology in schools.
    • Second we need teachers involved in curriculum and products for education
    • Third Microsoft is already working on this but it’s not as easy as it looks

    I think that educational software would be and occasionally is a very good thing. But developing it is not so easy. Getting it accepted by schools is even harder. Am I saying it should not be tried? Of course not, but it is too big a job even for the Gates Foundation. Here is what I think should be done.

    We need more teacher developed materials. The first text book (and I would argue my best one) was developed specifically to teach my introduction to programming course. I took the course as I had taught it, including the explanations, examples, quizzes and projects, and turned it into a textbook. It seemed to work well and I got a lot of good feedback from other teachers. Likewise one of the most popular downloads from has been a book of projects (now available for VB 6, VB .NET and C#) that were developed mostly from projects I had used with students.

    I am a firm believer in teacher developed resources. I wish more teachers would write textbooks for themselves. But that is never going to happen. Why? A whole bunch of reasons including the fact that most teachers don’t have time to write and do all the other things they have to do and still have a life. Publishers already believe, probably correctly, that they have too many textbooks to make a good profit. It is too hard to discover textbooks that are self published or published by smaller textbook companies. Now just think about how few teachers have the time and the technical ability to develop educational software.

    What we need is a framework where teachers can work with software developers to develop tools for (and in a sense from) the classroom. This includes people and it includes software that can be used to develop training tools.

    One example of the kind of thing I think will work is the ChemPad project out of Brown University. At Brown there is a chemistry course that is a critical part of the chemistry major. It is a stumbling block for many students because it requires that they be able to visualize molecules in three dimensions. Lots of students have trouble making that adjustment and so become lost to the major. The professor went to the Computer Graphics Group at Brown and asked for help.  The result is a program that allows students to draw a molecule in 2-dimensions and render the result in 3-dimensions. This model can be rotated and analyzed. This software is being used today and appears in early results to be very successful. Microsoft Research did supply some funds and Tablet PCs to help make this happen BTW. Microsoft through Microsoft Research funds a good many projects to develop educational software.

    Some of the work that went into ChemPad may be adaptable to other teaching problems in other subject matter areas. But it is going to take people with time, training, money and most of all passion for the subject to take advantage of tools like this.

    Efforts like this are expensive and require the cooperation of a lot of people. In the long run I think they will be worth it. But I don’t think it is a silver bullet. It’s not going to help unless teachers are trained and ready to use such tools. For every teacher who is willing to get the training and adapt to new tools there seem to be 10 who are going to resist. Schools of Education have to get busy here. This is a generational problem and we need to get started on it.

    We are faced with a sort of chicken and egg question here. Are teachers unwilling to use technology because there are no good tools for them to use or are there no good tools because teachers would out use them anyway? The answer is yes. Both are the problem.

    I think that convincing people (teachers, politicians, parents) that technology tools can make a difference is going to have to come before a really large scale effort to systematically change the way we run schools has to come first. We need schools with teachers and supportive administrators who are dedicated to finding smart ways to use the technology we have now. Once that happens and there is some evidence that it all works I think we’ll see others jump into the effort. Perhaps the School of the Future that is being constructed in Philadelphia will be that school.

    Who ever develops great educational software is going to need more than money. They are going to need teachers and schools ready to adopt it. I'm not sure we have much of that yet. What about your school? Is your school ready (financially, pedagogically, politically, emotionally) to accept dramatically new ways to teach and learn?

Page 4 of 11 (31 items) «23456»