Re: [fpc-devel] Format Function
On Mon, 28 Jan 2019, a...@aavani.net wrote: Hi, I am looking for a version of Format function that works with WideStrings. One way to implement this is to use something like the folllowing: function GetNames(const FirstName, LastName: WideString; ID: Integer): WideString; begin Result := ReadWideString(Format('%d %s %s', [ID, WideStringToUTF8(Name1), WideStringToUTF8(Name2)]) end; Is there any better way to do this? You can use the native functions: https://www.freepascal.org/docs-html/current/rtl/sysutils/wideformat.html https://www.freepascal.org/docs-html/current/rtl/sysutils/unicodeformat.html Michael.___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[fpc-devel] Format Function
Hi, I am looking for a version of Format function that works with WideStrings. One way to implement this is to use something like the folllowing: function GetNames(const FirstName, LastName: WideString; ID: Integer): WideString; begin Result := ReadWideString(Format('%d %s %s', [ID, WideStringToUTF8(Name1), WideStringToUTF8(Name2)]) end; Is there any better way to do this? Thanks, Amir ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
Daniël Mantione wrote: The difference is of scientific meaning. If there were no negative zero, the precision around zero would be halved. While true, its precision would be the same as the precision "around" all other numbers. 0 = -0.5 .. 0.4 1 = 0.5 .. 1.4 2 = 1.5 .. 2.4 etc... Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
On Thu, Oct 12, 2006 at 03:24:14PM +0200, Florian Klaempfl wrote: > 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. It does it means that the original number was negative before rounding. 0 is neither positive or negative but -0.000 is both correct and meaningful. The precision (4 digits) indicates that it is not exactly 0 but is slightly negative ie: x = -0.000 ==> x < 0.000 and x > -0.0005 ( rounding towards zero ) where x = 0.000 ==> x > 0.000 and x < 0.0005 ( rounding towards zero ) It is the implied precision that is causing you the problems. Besides the other problem is that converting decimal -1E-4 to binary results in an irrational binary number ( similar to 1/3 in decimal). As long as you use floating point numbers in normal computing tasks you need to be aware of the implied precision problems and do error checking in your code. John > > Well, despite the fact that -0.000 is probably indeed wrong in this case, a > mathematical view is often wrong when using an fpu :) > > > If I round something and the resulting value is zero, well zero is zero. > > Not +0 or -0. > > a. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: Re[3]: [fpc-devel] format function
Maybe this is off topic, but some interesting information about floating point operations could be found at http://vod.niif.hu/index.php?lg=en&mn=archive&eid=47&sm=listevent&secid=85. I recommend you to check "Can we trust floating-point numbers?" by Paul Zimmermann. ISO/IEC 10967-3 "Information technology -- Language independent arithmetic -- Part 3: Complex integer and floating point arithmetic and complex elementary numerical functions" is worth to check too. - Original Message - From: "Пётр Косаревский" <[EMAIL PROTECTED]> To: "FPC developers' list" Sent: Thursday, October 12, 2006 5:51 PM Subject: Re[3]: [fpc-devel] format function 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 checks"!). If you want the program to be more rough and scientist oriented, it will be one of only few "extra checks". ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[3]: [fpc-devel] format function
> 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 checks"!). If you want the program to be more rough and scientist oriented, it will be one of only few "extra checks". ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 the extremes. Anything done with infinity is infinity or zero, so that's not a "noticeable" difference IMHO. Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[2]: [fpc-devel] format function
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 http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 mean here. I said that for some fpu calculations the sign of zero matters. I understood that you asked for 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 examples of real-world cases where the sign of zero gives a different meaning to the result. What else did you expect? Jonas ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[2]: [fpc-devel] format function
> http://en.wikipedia.org/wiki/Negative_zero > Jonas Nice link: "In science, −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 −1." "Format" primarily produces strings for users, not for programmers. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[4]: [fpc-devel] format function
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. > > If the user is supposed to understand that "-0.000" means "a small negative > number", then it's ok. If the user will be terrified, it would be bad. Grandma is not the only user of a computer. A computer is a precision instrument, usable by scientists. Format is used to display numbers in scientific notation. 0 means "somewhere between 0 and 2^-127". -0 means "somewhere between -2^-127 and 0". The difference is of scientific meaning. If there were no negative zero, the precision around zero would be halved. Daniël___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 being succinct as ever :) Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[4]: [fpc-devel] format function
> 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 small negative number", then it's ok. If the user will be terrified, it would be bad. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: Re[2]: [fpc-devel] format function
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" Sent: Thursday, October 12, 2006 3:46 PM Subject: Re: Re[2]: [fpc-devel] format function On 12 okt 2006, at 15:41, Пётр Косаревский wrote: In the othe case, if the user is supposed to understand, that he looks at some representation of binary representation of a real number, "-0.000" obviously means "little negative number". No, it means the value 0, but with a negative sign. The value "-0" is representable in an exact way on any IEEE standard-compliant fpu. The reason is that fpu's have a separate bit to store the sign. So even if the mantissa and exponent show that it's the value zero, the sign bit can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Jonas___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
Jonas Maebe wrote: can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Like ? Micha ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: Re[2]: [fpc-devel] format function
On 12 okt 2006, at 15:41, Пётр Косаревский wrote: In the othe case, if the user is supposed to understand, that he looks at some representation of binary representation of a real number, "-0.000" obviously means "little negative number". No, it means the value 0, but with a negative sign. The value "-0" is representable in an exact way on any IEEE standard-compliant fpu. The reason is that fpu's have a separate bit to store the sign. So even if the mantissa and exponent show that it's the value zero, the sign bit can still be one (meaning that it's a negative zero). And for some fpu calculations this even matters. Jonas___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re[2]: [fpc-devel] format function
> >> 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 wrong when using an fpu :) > > If I round something and the resulting value is zero, well zero is zero. > > Not +0 or -0. > > a. It's a matter of tradition. If FPC is to behave like Delphi, the "question" is definitely a bug report. In the othe case, if the user is supposed to understand, that he looks at some representation of binary representation of a real number, "-0.000" obviously means "little negative number". And user may understand, that multiplying it by 1 he is not likely to get positive number. And it has nothing in common with FPU plus/minus zeroes in the example. I personally prefer "-0.000" in this case. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 wrong when using an fpu :) > If I round something and the resulting value is zero, well zero is zero. > Not +0 or -0. > a. > ___ > fpc-devel maillist - fpc-devel@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-devel ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 is taken to decide whether it should put the - sign or not. What does delphi do ? Not only that, but -0.000 is different from 0.000 (at least for the fpu) Jonas ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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 resulting string is > -0.000 > and not > 0.000 > Why? 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. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
Re: [fpc-devel] format function
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', [-0.0001]) > the resulting string is > -0.000 > and not > 0.000 > Why? Hmm, I'd guess that's because the (original) number is negative and the sign is not changed by rounding or chopping off digits. Vinzent. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel
[fpc-devel] format function
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? Andrea ___ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel