Anonymous user
Accumulator factory: Difference between revisions
m
→Customized number type
Line 2,183:
# Create the accumulator procedure.
result = proc (n: Number): Number =
# Create the accumulator procedure.
result = proc (n: Number): Number =
case
of kInt:
# Add an int to an int.
# Add a float to an int => change the kind of accumulator to float.
sum = Number(kind: kFloat, fval: sum.ival.toFloat + n.fval)
of
# Add an int to a float.
# Add a float to a float.
result = sum▼
sum.fval += n.fval
▲ result = sum
#---------------------------------------------------------------------------------------------------
|