Heather Donahue wrote: > On 11/5/02 11:50 PM, "Alain Pastor" <apastor@...> wrote: > > >> >>Heather Donahue wrote: >> >>>I like the subject line :-) >>> >>>Maybe my memory is failing but I thought that the type FIXED supported real >>>numbers. >>> >>>I would have hoped that dividing 16 by 10 would give me 1.6 (I'd even accept >>>1.05999) >>> >>>When I do this: >>> >>>dim as fixed testNum: testNum = 321.0 >>>dim as fixed timesTen >>>dim as fixed divTen >>> >>>timesTen = testNum * 10: print timesTen >>>divTen = testNum / 10: print divTen >>> >>>I get this: >>> >>>3210 >>>32 --> Should be 32.1 (or is it 32.09999?) >>> >>>Am I missing something or is FIXED broken? >>> >> >>Shouldn't you be using FixMul and FixDiv in those cases? > > > Good question but I find no mention of that in the FB Reference. If I > declare a variable as single I don't have to take care of the floating point > math myself. > > I could have sworn that I've used Fixed before and FB took care of the > computations. If it's a type that FB doesn't handle internally then it > shouldn't be mentioned so prominently in the manual. > > Even this doesn't work: > > dim as fixed timesTen > dim as single timesTenFloat > timesTen = 32.11554: print timesTen // prints 32 > timesTenFloat = timesTen: print timesTenFloat // prints 32 > > So internally FB is treating fixed as a long, pretty useless if you can't > even store a float into a fixed before passing it to a function that takes a > fixed variable. > I think you're right. It seems that Fixed is not a real type in FB, as A.G. would say it is just a placeholder to pass the correct number of bytes onto the Toolbox. You must handle the calculation doing some conversion I guess: dim x as fixed toolbox fn Fix2X(Fixed ) = double toolbox fn X2Fix(double) = Fixed x = fn X2Fix(12.2222) print fn Fix2x(x) or var# = fixedvalue \ 65536.0 Fixedvalue = var# * 65536 That would mean that you will have to store the number in a double variable, I suppose. Perhaps something like this: toolbox fn Fix2X(Fixed ) = double toolbox fn X2Fix(double) = Fixed dim temp as double dim testNum as fixed : testNum = 321.0 dim timesTen as fixed dim divTen as fixed temp = testNum timesTen = fn FixMul(fn X2Fix(temp), fn long2fix(10) ) temp = fn Fix2x( timesTen ) print temp temp = testNum divTen = fn FixDiv( fn X2Fix(temp), fn Long2Fix(10) ): temp = fn Fix2x( divTen ) print temp -- Cheers, A. Pastor