financial math
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
|
Not Categorized, Please Help
|
|