Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-10 Thread Joao Morais
On Fri, Mar 9, 2012 at 06:36, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 09 Mar 2012, at 10:23, Sven Barth wrote: The buzzword for this is Fixed Point Arithmetic. See here: http://en.wikipedia.org/wiki/Fixed-point_arithmetic And in principle, it's exactly what currency should use. And

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-09 Thread Sven Barth
Am 08.03.2012 13:14, schrieb Marcos Douglas: So, if you have two values to storage (amount of decimals is 4) e.g. 100.34524 and 2,000.2 you do: 100.34524 = 1003452 2,000.2 = 20002000 I never heard about this technique before. Very good! The buzzword for this is Fixed Point Arithmetic. See

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-09 Thread Jonas Maebe
On 09 Mar 2012, at 10:23, Sven Barth wrote: The buzzword for this is Fixed Point Arithmetic. See here: http://en.wikipedia.org/wiki/Fixed-point_arithmetic And in principle, it's exactly what currency should use. And in fact, it is what it does use in FPC on platforms that don't support an

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-08 Thread Marcos Douglas
On Thu, Mar 8, 2012 at 4:41 AM, Graeme Geldenhuys graemeg.li...@gmail.com wrote: On 8 March 2012 03:28, Marcos Douglas wrote: Integer math... what did you mean? Over the years we have experience many problems with currency, floating point and date/time calculations and storage. So we tweaked

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-08 Thread Graeme Geldenhuys
On 8 March 2012 14:14, Marcos Douglas wrote: So, if you have two values to storage (amount of decimals is 4) e.g. 100.34524 and 2,000.2 you do: 100.34524 = 1003452 2,000.2 = 20002000 Correct. We then implemented our own function [eg: M2AmountToCurr() ] which formats such a number [only

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Martin Schreiber
On Tuesday, 6. March 2012 14.13:17 Ludo Brands wrote: No, Currency is based on Extended on i386 and x86_64 (except win64!). There is also a lot of code in the rtl and fcl-db that supposes currency = double. Fe. Function CurrToStr(Value: Currency; Const FormatSettings: TFormatSettings):

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Zaher Dirkey
2012/3/6 Flávio Etrusco flavio.etru...@gmail.com I'm glad I never worked with banking/financial systems :-$ In accounting/financial systems there is Debit and Credit numbers it must equal and Debit - Credit = 0, with this bug it fail. I am an accountant and i know if there is 0.0001 diff in

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Graeme Geldenhuys
On Wednesday, 7 March 2012, Zaher Dirkey parm...@gmail.com wrote: In accounting/financial systems there is Debit and Credit numbers it must equal and Debit - Credit = 0, with this bug it fail. I am an accountant and i know if there is 0.0001 diff in balance sheet, my boss will fire me :P This

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Marcos Douglas
On Wed, Mar 7, 2012 at 7:43 PM, Graeme Geldenhuys graemeg.li...@gmail.com wrote: On Wednesday, 7 March 2012, Zaher Dirkey parm...@gmail.com wrote: In accounting/financial systems there is Debit and Credit numbers it must equal and Debit - Credit = 0, with this bug it fail. I am an

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Graeme Geldenhuys
On 8 March 2012 03:28, Marcos Douglas wrote: Integer math... what did you mean? Over the years we have experience many problems with currency, floating point and date/time calculations and storage. So we tweaked our software to handle such data slightly different. If a user enters and amount

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-07 Thread Zaher Dirkey
On Thu, Mar 8, 2012 at 3:28 AM, Marcos Douglas m...@delfire.net wrote: Integer math... what did you mean? Integer math = Currency or in DB numeric(18, 4) in Firebird create domain AMOUNT as numeric(18,4); On Thu, Mar 8, 2012 at 12:43 AM, Graeme Geldenhuys graemeg.li...@gmail.comwrote:

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Zaher Dirkey
On Mon, Mar 5, 2012 at 12:22 AM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: This particular problem could obviously be resolved by adding a currency-specific version of abs() Can i ask to add overload function for ABS(Currency) be a feature request in FPC? Thanks I am using last reversion

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread michael . vancanneyt
On Tue, 6 Mar 2012, Zaher Dirkey wrote: On Mon, Mar 5, 2012 at 12:22 AM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: This particular problem could obviously be resolved by adding a currency-specific version of abs() Can i ask to add overload function for ABS(Currency) be a feature

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Jonas Maebe
On 06 Mar 2012, at 13:05, michael.vancann...@wisa.be wrote: On Tue, 6 Mar 2012, Zaher Dirkey wrote: On Mon, Mar 5, 2012 at 12:22 AM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: This particular problem could obviously be resolved by adding a currency-specific version of abs() Can i ask

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread michael . vancanneyt
On Tue, 6 Mar 2012, Jonas Maebe wrote: On 06 Mar 2012, at 13:05, michael.vancann...@wisa.be wrote: On Tue, 6 Mar 2012, Zaher Dirkey wrote: On Mon, Mar 5, 2012 at 12:22 AM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: This particular problem could obviously be resolved by adding a

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Sven Barth
Am 06.03.2012 13:28, schrieb michael.vancann...@wisa.be: On Tue, 6 Mar 2012, Jonas Maebe wrote: On 06 Mar 2012, at 13:05, michael.vancann...@wisa.be wrote: On Tue, 6 Mar 2012, Zaher Dirkey wrote: On Mon, Mar 5, 2012 at 12:22 AM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: This

RE : [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Ludo Brands
Note that this requires compiler patching, because abs() is internal (it can be used in constant expressions). I would personally argue to do away entirely with the treat currency as a floating point type on i386 so it can use the 80x87, and instead map it implementation-wise

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Zaher Dirkey
On Tue, Mar 6, 2012 at 2:56 PM, Sven Barth pascaldra...@googlemail.comwrote: No, Currency is based on Extended on i386 and x86_64 (except win64!). Hmm, but it is break the balance in the budget of my customer. I resolved it by adding CurrABS function, but i don't think it is good idea. Best

Re: RE : [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Sven Barth
Am 06.03.2012 14:13, schrieb Ludo Brands: Note that this requires compiler patching, because abs() is internal (it can be used in constant expressions). I would personally argue to do away entirely with the treat currency as a floating point type on i386 so it can use the 80x87, and

RE : RE : [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Ludo Brands
There is also a lot of code in the rtl and fcl-db that supposes currency = double. Fe. Function CurrToStr(Value: Currency; Const FormatSettings: TFormatSettings): string; begin Result:=FloatToStrF(Value,ffGeneral,-1,0,FormatSettings); end; Or TCurrencyField =

Re: RE : [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Jonas Maebe
On 06 Mar 2012, at 14:13, Ludo Brands wrote: There is also a lot of code in the rtl and fcl-db that supposes currency = double. Fe. Function CurrToStr(Value: Currency; Const FormatSettings: TFormatSettings): string; begin Result:=FloatToStrF(Value,ffGeneral,-1,0,FormatSettings); end;

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Jonas Maebe
On 06 Mar 2012, at 13:28, michael.vancann...@wisa.be wrote: As far as I know, Currency is always a scaled int64, and didn't interpret the request as a request to change that. The problem is that on i386 (and in Delphi on i386), operations on the currency type are handled using the fpu.

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-06 Thread Flávio Etrusco
On Tue, Mar 6, 2012 at 12:11 PM, Jonas Maebe jonas.ma...@elis.ugent.be wrote: On 06 Mar 2012, at 13:28, michael.vancann...@wisa.be wrote: As far as I know, Currency is always a scaled int64, and didn't interpret the request as a request to change that. The problem is that on i386 (and in

[fpc-pascal] Currency and ABS(-674.59)

2012-03-04 Thread Zaher Dirkey
I found this problem in Delphi and FPC, please test it and confirm if it is a bug. --- program test_abs_curr; uses sysutils; var a: Currency; begin a := 674.59; if aabs(-a) then writeln('not equal') else writeln('equal'); end. --- I am using

Re: [fpc-pascal] Currency and ABS(-674.59)

2012-03-04 Thread Jonas Maebe
On 04 Mar 2012, at 22:31, Zaher Dirkey wrote: I found this problem in Delphi and FPC, please test it and confirm if it is a bug. The problem is caused by the facts that a) on i386, currency operations are calculated using the 80x87 floating point unit b) there is no separate abs() for