Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming Books Media Book Reviews IT Technology

Math Toolkit for Real-Time Programming 153

oxgoad writes "Need a closed-form algorithm to derive square roots? Stymied by strange and scary results from your favorite compiler's math library? Math Toolkit for Real-Time Programming by Jack W. Crenshaw attempts to shed some numerical light. Read on for the goods." Oxgoad's review continues below.
Math Toolkit for Real-Time Programming
author Jack W. Crenshaw
pages 466
publisher CMP Books
rating 8
reviewer oxgoad
ISBN 1929629095
summary A casual discussion of algorithms ranging from abs to numerical calculus.

Who & What

Jack W. Crenshaw, Ph.D. (Physics) wrote his first computer program in 1956 for an IBM 650. He has been working with real-time software for embedded systems ever since -- contributing several years to NASA during the Mercury, Gemini, and Apollo programs. In addition to other activities, he is currently a contributing editor for Embedded Systems Programming magazine and author of the Programmer's Toolbox column.

In Math Toolkit for Real-Time Programming, his effort is focused on describing the pitfalls of vendor-provided math libraries and providing robust replacements. In section one he gives a thorough overview of constants and the various manners in which to declare them, naming conventions, and error handling. As the work progresses, in section two, he builds a library of proven algorithms ranging from square roots to trigonometrical functions to logarithms. Did you suffer through calculus in college with a barely passing grade? Section three will teach you more about numerical calculus in a half-hour than you may have learned in three semesters.

Kudos

Math Toolkit is written in an easy to understand anecdotal manner. You might be tempted to think that the author was animatedly relating the history of computing square roots while having lunch with you. This method works very well and keeps what could be a rather heavy subject from becoming too much of a burden. Most chapters have historical tidbits liberally sprinkled throughout.

Even if college algebra left you with post-traumatic stress disorder, you will not have any trouble with section two. Indeed, you may find yourself intently following the author on the trail of the perfect arctangent algorithm -- much as a sleuth on the trail of a villain.

The depth of knowledge shown, and its presentation, is exceptional. The author's years of experience are evident in his self-confident writing style. You will rarely see a clearer overview of numerical calculus.

Quibbles

The cover of the book states: "Do big math on small machines." This, combined with the Real-Time Programming phrase in the title, might lead one to believe that the book's primary audience is intended to be the embedded microcontroller crowd. Sadly, not so. There is very little here for the die-hard assembler programmer other than some very handy integer square root and sine routines - and these examples are in C++. Based on the cover, I would have liked to see a greater emphasis on processors lacking a floating point unit. Also, some code examples in pseudo-assembler would have been welcome, as the author chose C++ as the language of choice for all examples.

Crimes

As is so often the case nowadays, there are various typographical errors scattered throughout. This seems to be an epidemic in current technical books. Fortunately, it didn't affect the readability of Math Toolkit.

Conclusions

I believe Math Toolkit for Real-Time Programming would be a great, perhaps mandatory, addition to the bookshelf of anyone that is involved in writing code that has a heavy math component. Other than the somewhat misleading cover, I cannot find anything truly negative to say about this work. Congratulations are in order to Mr. Crenshaw on a job well done.

The book also includes a CD-ROM of all example source code. In reality, to get the best benefit from the book, you should mostly ignore the CD-ROM and work through the examples. To quote the author: "Never trust a person who merely hands you an equation."

Table of Contents

  1. Getting The Constants Right
  2. A Few Easy Pieces
  3. Dealing with Errors
  4. Fundamental Functions
  5. Getting the Sines Right
  6. Arctangents: An Angle-Space Odyssey
  7. Logging in the Answers
  8. Numerical Calculus
  9. Calculus by the Numbers
  10. Putting Numerical Calculus to Work
  11. The Runge-Kutta Method
  12. Dynamic Simulation
  • Appendix A: A C++ Tools Library

Disclosure

I received a review copy of this book from the publisher. Thus, my loyalties and opinions may be completely skewed. Caveat Lector.


You can purchase Math Toolkit for Real-Time Programming from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Math Toolkit for Real-Time Programming

Comments Filter:
  • by HealYourChurchWebSit ( 615198 ) on Thursday October 10, 2002 @10:22AM (#4423656) Homepage
    Back in the day, a book like this would have been a real life saver for those of us slugging it out with brain-damaged operating systems (e.g. MS-DOS). From things like MIDI sequencers to guidance systems, the need for real-time speed was a real issue.

    However, with the the maturity of operating systems, many of them now include device drivers, APIs, objects and other goodies that insulate the average programmer from the hassle of issues like latency. So my question is, other than good academic study, would it pay for the rest of us to spend the $$ on such a book?

    Though I admit, having to write my share of real-time apps back in the day has me curious enough to put the book on my wishlist.
  • by beanerspace ( 443710 ) on Thursday October 10, 2002 @10:27AM (#4423681) Homepage
    Someone marked this question redundant? Guess that shows you jerks are everywhere.

    Hey, I understand completely what you're saying. I for one am glad I don't have to deal with such as latency and pre-emption. In fact, here is a link to a nifty article entitled "Real Time Issues in Linux [helsinki.fi]" that essentially sums up what you asked with a resounding yes.
  • by GGardner ( 97375 ) on Thursday October 10, 2002 @10:32AM (#4423711)
    If you want to control a robot by putting a bunch of cheap 8-bit PICs on board, you are going to be hard pressed to find any nice device drivers, API, objects and other goodies.
  • by Havokmon ( 89874 ) <rick.havokmon@com> on Thursday October 10, 2002 @10:39AM (#4423748) Homepage Journal
    I wonder how much better could we be if coders knew basic math

    Funny this topic should come up. I just did a 'Store Locator' for the company I work for (I'm the IT Manager, belive it or not). All I have is your basic HS diploma, and in creating the search, I realized I don't know a damn thing about sine and cosine. I don't know how they're used, or how they're applied. I have a feeling that they're somehow related to geometry (which makes sense, seeing I have to get a distance between two points on a curve - the earth), but I'm not sure.

    Sure, it's probably taken me longer to write this post, than it took to find the php code I used as a basis for the search, but how much math is REALLY needed overall?

    I slept through school, I did really bad, all because I felt it was worthless. I did feel that my business class, business law, and basic Algebra has been useful. But overall, it wasn't worth my time. Hell I had a physics teacher who'd pick on me because I was flunking (it's amazing what good test grades + 0 homework does to you), but I just found physics interesting - jeez, it was only HS. I was testing the waters, not padding my GPA. I believe that's what's HS is FOR.

    And if you KNOW what you want to do (I knew I wanted to fix/program computers when I played on my Apple ][ in 6th grade), what the hell is college for?

    The ease of the internet sure hasn't helped my perception.

    Am I the only one?

  • by ohboy-sleep ( 601567 ) on Thursday October 10, 2002 @10:40AM (#4423755) Homepage
    When I went for my Comp Sci bachelor's I was amazed at how many math-phobics there were in my Comp Sci classes. As part of earning the degree you had to take 4 specified math classes (Calc 1 & 2, Linear Systems, Probability). You only had to take one more math class to get a minor in mathematics, Calculus 3.

    Now I've always been big on math but I was kind of surprised at how few people were willing to take a single class to earn a full-fledged minor.
  • Forth Algorithms (Score:4, Interesting)

    by Anonymous Coward on Thursday October 10, 2002 @10:41AM (#4423759)
    The Forth literature contains many examples of high-performance hardware-integer-math-only routines. A core feature of most Forth algos is rescaling to a power of two space at the start of the algo and from it at the end. This allows bit shift operators to do their stuff. It can take non-trivial fiddling to rescale algorithms - hence, it's nice to just look them up.

    Unfortunately, it's tricky to find Forth books these days.

    That's a shame, because along with Smalltalk, Lisp and APL, I think Forth is one of the "mind expanding" languages all programmers should at least experience, instead of just deciding C/Java/C++/VB is the one true language.

  • Math in CS programs (Score:2, Interesting)

    by Diver777 ( 614939 ) <jjtimmer@stud e ... th.uwaterloo.ca> on Thursday October 10, 2002 @10:43AM (#4423769) Homepage

    I don't know of other programs, but I know at the University of Waterloo (where I am a computer science student), we must take quite a lot of math courses, ranging from linear algebra, calc, classical algebra, combinatorics & optimization and statistics. The math content for the CS program is very high, and in the end you get a BMath degree.

    Maybe this is different at other schools (well, actually I know it is at most, most don't do nearly as much math), but I would hope not. I think to be a solid programmer a solid math background is a requirement.

    oh, and btw, for anyone nitpicking, UW now offers a BCS program, as well as the typical BMath Honours CS. The BCS seems to offer a bit more flexibility, so BCS students may not choose to take 'as much' math.

  • by wfmcwalter ( 124904 ) on Thursday October 10, 2002 @10:44AM (#4423779) Homepage
    This is a subject that's rather neglected - three years of college math didn't go very far in letting me understand how math (fp and otherwise) is actually done in discrete systems.

    A year (or so) ago I attended a lecture given by Guy Steele (of Lisp/Java/ Crunchly fame) on his proposal to alter how IEEE floating point numbers are mapped to real numbers. It quickly flew over my head, but gave a great insight into the whole field. Steele then had a fair old "discussion" with the one person in the audience whose head hadn't been overflown (sic), as there was plainly still much controversy left in this area. On trying to do some "why didn't I get this stuff at college" reading, I found there wasn't a great deal of literature.

    The reviewer's concern that coprocessor-less systems should be covered is valid, but I'm not sure going as far as assembly is necessary. For example, I once had the privilige of reading through Hitachi's libm implementation for their H8 series microprocessor/microcontroller (one would be generous to call H8 a 16-bit system, and ungenerous to call it an 8-bit system). With one small exception (I think the cos table lookup) the whole thing was in (quite readable) C, and (at least for basic libm stuff) performance was perfectly acceptable. For didactic purposes, a C (or sane C++) implementation would be the thing one would want to find in a book - I get very annoyed at embedded books where the examples are written in asm for the author's favourite (obscure) microcontroller.

  • Yes. Banks, old satallite programs, messaging systems...etc.

    I work with a group of eight other people updating 40 year old Assembler on an IBM Series 1. Something tells me that if this was included in our training programs, those that are
    SUF
    FER
    ING
    through the digit-crunching wouldn't have such a hard time. Most people consider this back-in-the-day, but there's an aaaawwwful lot out there that still reeks of old german engineering, and chunk-button ATMs.
  • by Svartalf ( 2997 ) on Thursday October 10, 2002 @10:58AM (#4423869) Homepage
    Embedded != Assembly coding.

    To be honest, a lot of embedded coding is done with C or C++ these days. I've been following Crenshaw's articles in Embedded Developer magazine for years now. He explains a lot of what they try to teach in college Calc, etc. in simple, practical terms, and reduces it to usable algorithms.

    I'd probably buy the book and add it to my shelf.
  • College Math (Score:3, Interesting)

    by BobTheJanitor ( 114890 ) on Thursday October 10, 2002 @11:04AM (#4423907) Homepage
    I graduated as a Math/CS double major from Drake University, where almost all CS majors also got a Math degree because the CS prereqs covered all but 3 of the Math prereqs. It has actually helped me enormously as a programmer to know math: in the past month, I've needed transformation matrices, sine/cosine stuff, and a bunch of other things that, granted, could have been lifted verbatim from Google groups, but it's often faster (and the code is better) if I just do it myself.
  • Link & More (Score:1, Interesting)

    by mccormick ( 40772 ) on Thursday October 10, 2002 @11:05AM (#4423910)
    That's it. For those who want the quick link for the Let's Write a Compiler, right here [iecc.com] (http://compilers.iecc.com/crenshaw/.) I really hope that Crenshaw might write again about compilers. I agree with the Pascal and 68k part -- they're old, and even some of the approach taken by the tutorial is probably not up to speed with modern practices. But hey, at least it gives a good historical account.
  • by IncohereD ( 513627 ) <mmacleod@ieeeEULER.org minus math_god> on Thursday October 10, 2002 @11:06AM (#4423915) Homepage
    This is pretty much Waterloo's claim to uniqueness, is it not? Something about being the only Univeristy in Canada with a math _Faculty_?

    I think this may provide some insight into whether or not it's a GoodThing for CS students to have more math in their degrees. Microsoft hires more programmers from Waterloo than anywhere else. And just look at the QUALITY of their code. :)

    On a somewhat tangential note, I'm in Communications Engineering at Carleton, and we badly need a stochastics course in our program, so Digital Comm doesn't keep flying over our heads. Sometimes more math is good.
  • by A nonymous Coward ( 7548 ) on Thursday October 10, 2002 @11:07AM (#4423920)
    I've been programming since 1968, and very little had anything to do with math. People give me the same line, wow, I'm no good with math, I couldn't program, and don't believe me when I say computers add and subtract, multiply once in a while (array subscripting usually), and hardly ever divide.

    Scientific or engineering programming, they need the math because they are math programming. The rest, forget it, maybe you add some numbers for a shopping cart, multiply for sales tax, but programming has little use for math.

    I learned long ago that when an 8 bitter needs trig functions, you use a look up table generated externally.
  • by joto ( 134244 ) on Thursday October 10, 2002 @11:07AM (#4423924)
    Not being exactly a math whizard myself, I found this book extremely entertaining. It's pretty easy to see that the author is a heavy follower of the KISS philosophy. He tries to keep it simple not just in his code, but also in his explanations. It is possible to understand most of his explanations, even if you don't know much about differential equations, fft's or anything else.

    As for the title, I agree it's a bit misleading. The book has pretty little to do about real-time (in fact nothing, as far as I could see). What it really should be called is "Computer arithmetic and a little of numerical methods for dummies". This book will help you understand how to write your own libm, and give you some ideas for more advanced tasks, but that's about it.

    For me, who didn't know much of this stuff, it was very interesting. It will probably not save you that course in numerical algorithms (which I for one haven't taken), but even then, it will probably contain some interesting tidbits you didn't know.

    On the other hand, if you have years of experience in writing computer math routines, it will probably quickly become dull, but that's true about anything you already know.

  • by DocTillo ( 615220 ) on Thursday October 10, 2002 @11:17AM (#4424034) Homepage
    Not all computers are desktop PCs. Have you ever heard of Palm Pilots? These things are slow! I searched some time to find a decent integer square root routine to calculate object distances in my elite for palmos game [harbaum.org]. I would have loved such a book ...
  • Decimal libraries (Score:3, Interesting)

    by Tablizer ( 95088 ) on Thursday October 10, 2002 @11:43AM (#4424335) Journal
    As a biz-app programmer, I am bothered by too much attention given to floating point math and not enough to decimal math. A decimal-centric approach would give better results for monetary calculations, because any truncation and rounding are at decimal (base-10) boundaries instead of base-2 boundaries. It gives results more like one expects doing it by hand on paper, which shapes most peoples' perceptions of what they expect (and the customer is always right, even if they are boneheads).

    The only library I know that supports it is the BC-library sometimes used with PHP. (Well, I guess you could say that COBOL has such also.) It actually uses strings to hold the results so that there is no machine-based limitation on precision size. Plus, that improves its cross-language use since almost everything supports dynamic strings these days.

    (Not the fasted approach I suppose, but most biz apps are not math intensive anyhow. Most code is devoted to comparing strings, codes, and ID's and moving things around from place to place. IBM used to include decimal-friendly operations in its CPU's. Those days seem gone for some reason, yet biz apps are still a huge domain.)
  • Amazon link, too (Score:2, Interesting)

    by tibbetts ( 7769 ) <jason@@@tibbetts...net> on Thursday October 10, 2002 @12:39PM (#4424899) Homepage Journal

    For those who don't support Slashdot's Amazon embargo, here's their link to the book [amazon.com]. Not only are they selling the book for $35, they have 25 sample pages, including the entire index and the first half of the first chapter. (And no, I'm not in Amazon's affiliates program and don't make a dime if you buy the book using the link that I provided, as a quick glance at the URL will prove.)

  • by Daniel Dvorkin ( 106857 ) on Thursday October 10, 2002 @02:08PM (#4425752) Homepage Journal
    Well, see, I'm a database guy too. I split my day pretty much equally between SQL and PHP. A lot of people may not consider that "real programming." I do, and in fact I've done some pretty heavy-duty scientific application programming in that past, and I'm here to tell you, I use my math skills just as much now as I did then. Because I don't just write queries and interfaces; I write them with absolutely fanatical attention to detail, and I subject everything I put up on my company's server to the kind of rigorous scrutiny I learned in set theory and algorithm analysis classes. And as a result, it works, and it works well, and on the rare occasions that something doesn't work as well as it should, I know how to fix it. The bigger applications get, the less meaningful the 90/10 theory really is -- for very big applications, a whole of bunch of seemingly trivial speed and scalability tweaks add up to big improvements down the road.
  • integer square root (Score:2, Interesting)

    by Mr Z ( 6791 ) on Thursday October 10, 2002 @04:46PM (#4427316) Homepage Journal

    If you still need a decent integer square root algo, check out this page. [azillionmonkeys.com] I used the mborg_isqrt2 variant on that page as a starting point for writing my highly optimized Intellivision version [spatula-city.org] for SDK-1600. [spatula-city.org] My optimized version takes about 600 - 700 cycles for a 16-bit square root, on a machine where most operations take 6 to 8 cycles. (The version I was replacing took 4000 - 10000 cycles.)

    This book looks like it might be interesting to me. Here at work, we had our own math expert, but he's retired (or semi-retired). We've contracted with him to do math libraries, and that works for now. But what about 10 years from now? There's a lot of subtlety in some of these algorithms (it's not always just as easy as whipping through a Taylor series expansion), so it's probably time someone in our group started learning. :-)

    --Joe

Living on Earth may be expensive, but it includes an annual free trip around the Sun.

Working...