1. financial math
- Posted by Jacques Deschenes <desja at QUEBECTEL.COM> Jun 24, 1997
- 662 views
I seem to me that it would be easy to write financial math function in euphoria. One could consider number as string and work on each of the string character. example: -- infinite precision sum function sum(sequence a, sequence b) sequence result integer d, c if length(a) < length(b) then while length(a) < length(b) do a = '0' & a end while else while length(b) < length(a) do b = '0' & b end while end if for i = 1 to length(a) do a[i] = a[i] - '0' b[i] = b[i] - '0' end for c = 0 result = {} for i = length(a) to 1 by - 1 do d = a[i] + b[i] + c if d > 9 then c = 1 d = d - 10 else c = 0 end if result = d+'0'&result end for if c then result = c+'0'&result end if return result end function puts(1, sum("115123451","116789")) As you see numbers can be of any size. same can be done for others operators. Regards, Jacques Deschenes Baie-Comeau, Quebec Canada desja at quebectel.com
2. Re: financial math
- Posted by Daniel Berstein <architek at GEOCITIES.COM> Jun 24, 1997
- 636 views
Jacques Deschenes wrote: > I seem to me that it would be easy to write financial math function in > euphoria. > One could consider number as string and work on each of the string character. Je,je,je you move faster than me ;) I was writting such a routine when I read your mail Jacques. I have already implemented addition,subtraction and multiplication, tomorrow I'll finish divition and I'll upload it to my webpage. Curiosity: I was using the same variable name, "result". But note that such a routine is not *that* acurrate in some circumstances: atom x x = 1/3 --x is 0.333333333333333 (15 threes) x = x * 3 --x is 1 Using "string" math 1/3 would be 0.333333333333333... but x*3 would be 0.999999999999999.... -- Regards, Daniel Berstein architek at geocities.com http://www.geocities.com/SiliconValley/Heights/9316
3. Re: financial math
- Posted by mark honnor <m.honnor at XTRA.CO.NZ> Jun 24, 1997
- 650 views
Maybe a set of functions could be used that store numbers as fractions rather than decimals, a sequence {x,y} could be used and when the decimal value is needed you divide x by y. I will have a quick go at this soon. --Augorian;