On Fri, 2007-12-07 at 17:04 -0800, Alan Wolfe wrote: > I just finished writing some pretty intricate code using floating > point and man, i hit so many problems...i was basically doing a "maze > solving algorithm" on a bunch of intersecting line segments and so i > was keeping track of where along a line the code was currently and > looking for intersections beyond that position. > > Because of precision problems, it would sometimes find the same > segment as the "next intersection" as it just came down and a couple > other wierd problems. > > I tried playing with adding epsilons to the floats to counter act the > precision issues which made other issues (really close intersections > wouldnt get picked up). > > Eventually i had to do more heuristic logic instead of straight up > mathematical decisions because no matter what i did mathematically i > couldn't get it to work right. > > I've worked a little bit with fixed point, but IMO it seems like it > really wouldnt solve the precision problems would it? > > What benefits besides speed do you get from using fixed point vs > floating point? (: On modern CPUs with floating point hardware floating point is *much* faster than integer arithmetic. On machines without floating point fixed point is faster than using a software implementation of floating point. So, for most cases speed is the only reason to use fixed point and then only on machines without floating point hardware. OTOH, and it is a big other hand, sometimes you need more precision than you can get with hardware floating point. Think about it, single precision floating point gives you 25 bits of precision (before you say no to the 25 bits check out the way IEEE floating point handles the high order bit of the factional part of a float). A 32 bit fixed point has 31 bits, or 32 if you go unsigned, of precision. You have to go to double precision to get better in floating point. Also, on 64 bit machines pixed point gives you 63 bits of signed precision in fixed point. Of course I am leaving out a lot of details here. But fixed point can give you a lot better precision in the same number of bits as a float. It can also give you much better control (and awareness) of precision problems than you get with floating point. It can also force you to write assembly code and do some other odd things to make it work. Personally, I am very glad that I can just use double precision on a PC and not have to worry about fixed point. But, I have done a *lot* of fixed point programming. It takes a while to understand it, but learning it will help you get the arithmetic right in your code for the rest of your life. Of course, taking a good numerical analysis class can have the same effect and not hurt nearly as much. Bob Pendleton > > On 12/7/07, Jeremiah Martell <inlovewithgod@xxxxxxxxx> wrote: > > Hello! > > > > Thanks for allowing me to use your fixed point code. It's actually > > very valuable to me! :-) > > > > I plan on using fixed point for my physics code, so that I have a > > little more control of the maths involved so nothing "crazy" happens. > > It's also nice if I ever want to make a "record your game" feature, as > > fixed point will be the same on all machines, whereas I've heard there > > can be differences with floating point operations. > > > > Thanks again! > > > > - Jeremiah Martell > > http://inlovewithGod.com > > > > --------------------- > > To unsubscribe go to http://gameprogrammer.com/mailinglist.html > > > > > > > > --------------------- > To unsubscribe go to http://gameprogrammer.com/mailinglist.html > > > -- +--------------------------------------+ + Bob Pendleton: writer and programmer + + email: Bob@xxxxxxxxxxxxx + + web: www.GameProgrammer.com + + www.Wise2Food.com + + nutrient info on 7,000+ common foods + +--------------------------------------+ --------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html