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

2012-03-10 Thread Joao Morais
On Fri, Mar 9, 2012 at 06:36, Jonas Maebe 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 in fact, it is > wh

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-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 here

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-08 Thread Marcos Douglas
On Thu, Mar 8, 2012 at 4:41 AM, Graeme Geldenhuys 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 > our software

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 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 wrote: > This is why our accounting app uses Inte

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 Marcos Douglas
On Wed, Mar 7, 2012 at 7:43 PM, Graeme Geldenhuys wrote: > > > On Wednesday, 7 March 2012, Zaher Dirkey 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.000

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

2012-03-07 Thread Graeme Geldenhuys
On Wednesday, 7 March 2012, Zaher Dirkey 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 is why our acco

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

2012-03-07 Thread Zaher Dirkey
2012/3/6 Flávio Etrusco > 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 balance sheet, my boss

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: TFormatS

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 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 Delphi on i386

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. Th

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; F

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 > > > > TCurre

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 inste

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 wrote: > 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 Regards Zaher Dirkey __

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 > imple

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 wrote: This particular problem could obviousl

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 wrote: This particular problem could obviously be resolved by adding a currency-specific version of ab

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 >wrote: This particular problem could obviously be resolved by adding a currency-specific version of abs() Can i ask to add overload function fo

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 wrote: 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? Yes, please ad

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 wrote: > 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 of Lazarus, FPC 2.6 Bes

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 curre

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

2012-03-04 Thread Jeppe Græsdal Johansen
Den 04-03-2012 22:31, Zaher Dirkey skrev: 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 a<>abs(-a) then writeln('not equal') else writeln('equ

[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 a<>abs(-a) then writeln('not equal') else writeln('equal'); end. --- I am using l