[fpc-devel] format function

2006-10-12 Thread Andrea Mauri
Dear all, this is my first mail to this mailing list, I'm not sure this is the correct one to post this topic. I noticed a strange behavior of the format function. I'm not sure it can be considered as a bug. If I use format('%.3f', [-0.0001]) the resulting string is -0.000 and not 0.000 Why?

Re: [fpc-devel] format function

2006-10-12 Thread Vinzent Hoefler
On Thursday 12 October 2006 12:16, Andrea Mauri wrote: Dear all, this is my first mail to this mailing list, I'm not sure this is the correct one to post this topic. I noticed a strange behavior of the format function. I'm not sure it can be considered as a bug. If I use format('%.3f',

Re: [fpc-devel] format function

2006-10-12 Thread Michael Van Canneyt
On Thu, 12 Oct 2006, Andrea Mauri wrote: Dear all, this is my first mail to this mailing list, I'm not sure this is the correct one to post this topic. I noticed a strange behavior of the format function. I'm not sure it can be considered as a bug. If I use format('%.3f', [-0.0001]) the

Re: [fpc-devel] format function

2006-10-12 Thread Jonas Maebe
On 12 okt 2006, at 14:22, Michael Van Canneyt wrote: I noticed a strange behavior of the format function. I'm not sure it can be considered as a bug. If I use format('%.3f', [-0.0001]) the resulting string is -0.000 and not 0.000 Why? Because your number is negative... The original number

Re: [fpc-devel] format function

2006-10-12 Thread Andrea Mauri
Michael Van Canneyt wrote: Because your number is negative... The original number is taken to decide whether it should put the - sign or not. What does delphi do ? Michael. ___ Delphi gives 0.000 as result. a.

[fpc-devel] Round function

2006-10-12 Thread Andrea Mauri
Using round function I implemented the RoundTo function as in Delphi: type TRoundToRange = -37..37; function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double; var LFactor: Double; begin LFactor := IntPower(10, ADigit); Result := Round(AValue / LFactor) * LFactor; end; In

Re: [fpc-devel] Round function

2006-10-12 Thread Graeme Geldenhuys
A week or two ago, I also found a problem with the Banker's Rounding in Free Pascal. As far as I could see, with my tests I did, compared to Delphi an know results with set values, there is a bug in FPC implementation. I might have forgotten to report it in Mantis though. I will double check.

Re: [fpc-devel] format function

2006-10-12 Thread Andrea Mauri
Jonas Maebe wrote: Not only that, but -0.000 is different from 0.000 (at least for the fpu) Jonas In a mathematical way of view I think that -0.000 has no meaning. If I round something and the resulting value is zero, well zero is zero. Not +0 or -0. a.

Re: [fpc-devel] format function

2006-10-12 Thread Florian Klaempfl
Andrea Mauri wrote: Jonas Maebe wrote: Not only that, but -0.000 is different from 0.000 (at least for the fpu) Jonas In a mathematical way of view I think that -0.000 has no meaning. Well, despite the fact that -0.000 is probably indeed wrong in this case, a mathematical view is often

Re: Re[2]: [fpc-devel] format function

2006-10-12 Thread Christian Ulrich
when the statement if (-0 = 0) is true then RoundTo schould not return an numer like -0 ?! i think the point of view of an fpu is in the round functions not nessesary 0 is 0 and not -0 - Original Message - From: Jonas Maebe [EMAIL PROTECTED] To: FPC developers' list

Re: [fpc-devel] format function

2006-10-12 Thread Vinzent Hoefler
On Thursday 12 October 2006 13:46, Micha Nelissen wrote: Jonas Maebe wrote: can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Like ? Divide by signed zero. That decides if the result is positive or negative infinity. :D Vinzent.

Re[4]: [fpc-devel] format function

2006-10-12 Thread Пётр Косаревский
representable in an exact way on any IEEE standard-compliant fpu. The Of course. But the result of format is user-oriented. User is not supposed to know about negative zero, denormal numbers, negative infinity and the whole IEEE 754. If the user is supposed to understand that -0.000 means a

Re: [fpc-devel] format function

2006-10-12 Thread Jonas Maebe
On 12 okt 2006, at 15:46, Micha Nelissen wrote: Jonas Maebe wrote: can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Like ? http://en.wikipedia.org/wiki/Negative_zero Jonas ___ fpc-devel

Re: [fpc-devel] format function

2006-10-12 Thread Michael Van Canneyt
On Thu, 12 Oct 2006, Jonas Maebe wrote: On 12 okt 2006, at 15:46, Micha Nelissen wrote: Jonas Maebe wrote: can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Like ? http://en.wikipedia.org/wiki/Negative_zero hehe, Jonas

Re: [fpc-devel] format function

2006-10-12 Thread Micha Nelissen
Michael Van Canneyt wrote: Like ? http://en.wikipedia.org/wiki/Negative_zero Jonas being succinct as ever :) And not answering the question ... sigh. As shown there, you never notice the difference in result. Micha ___ fpc-devel maillist -

Re[4]: [fpc-devel] format function

2006-10-12 Thread Daniël Mantione
Op Thu, 12 Oct 2006, schreef ???: representable in an exact way on any IEEE standard-compliant fpu. The Of course. But the result of format is user-oriented. User is not supposed to know about negative zero, denormal numbers, negative infinity and the whole IEEE 754.

Re[2]: [fpc-devel] format function

2006-10-12 Thread Пётр Косаревский
http://en.wikipedia.org/wiki/Negative_zero Jonas Nice link: In science, #8722;0 may be used to denote a quantity which is less than zero, but which is too small in magnitude to be rounded down to #8722;1. Format primarily produces strings for users, not for programmers.

Re: [fpc-devel] format function

2006-10-12 Thread Jonas Maebe
On 12 okt 2006, at 16:31, Micha Nelissen wrote: Michael Van Canneyt wrote: Like ? http://en.wikipedia.org/wiki/Negative_zero Jonas being succinct as ever :) And not answering the question ... sigh. As shown there, you never notice the difference in result. I don't understand what you

Re[2]: [fpc-devel] format function

2006-10-12 Thread Daniël Mantione
Op Thu, 12 Oct 2006, schreef ???: Format primarily produces strings for users, not for programmers. Why do you think that scientific notation is used by default? Daniël___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] format function

2006-10-12 Thread Micha Nelissen
Jonas Maebe wrote: examples when you answered with Like?. I therefore gave a link to a wikipedia article which shows that the sign matters e.g. when dividing by zero (positive or negative infinity), and the article also gives some Well I meant a real practical difference, not something at

Re[3]: [fpc-devel] format function

2006-10-12 Thread Пётр Косаревский
Why do you think that scientific notation is used by default? I personally prefer -0.000 in this case. It's just a personal preference. A weak argument: If you write a program grandma should use, you can always add an extra check if she complains (and it will be only one of the many extra

Re: Re[3]: [fpc-devel] format function

2006-10-12 Thread Rimgaudas Laucius
Maybe this is off topic, but some interesting information about floating point operations could be found at http://vod.niif.hu/index.php?lg=enmn=archiveeid=47sm=listeventsecid=85. I recommend you to check Can we trust floating-point numbers? by Paul Zimmermann. ISO/IEC 10967-3 Information

[fpc-devel] StrDispose FreeMem with size

2006-10-12 Thread Micha Nelissen
Hi, At cutils line 926, FreeMem is called for p with size strlen(p)+1. Could it be that actually a much bigger block was allocated, and not size strlen(p)+1 ? Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org