float/decimal mix-up when doing financial calculations

I finally isolated the bug I'm experiencing while
trying to produce an expense voucher for my August
trip.

Try the attached ala...


connolly@dirk:~/w3ccvs/WWW/2000/10/swap$ python cwm.py
test/datatypes/dec-div.n3  --think


and out comes...


#Processed by Id: cwm.py,v 1.162 2004/08/08 01:44:49 syosi Exp
        #    using base
file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/datatypes/dec-div.n3
        Traceback (most recent call last):
  File "cwm.py", line 635, in ?
    doCommand()
  File "cwm.py", line 543, in doCommand
    think(workingContext, mode=option_flags["think"])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 60, in
think
    return InferenceTask(knowledgeBase, ruleFormula, mode=mode,
repeat=1).run()
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 220, in
run
    return self.runSmart()
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 208, in
runSmart
    total += cy.run()
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 349, in
run
    found = rule.once()
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 441, in
once
    total = query.resolve()
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 584, in
resolve
    return self.unify(self.queue, self.variables, self.existentials)
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 821, in
unify
    bindings.copy(), nb, evidence = evidence + [reason])
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 752, in
unify
    nbs = item.tryBuiltin(queue, bindings, heavy=0, evidence=evidence)
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/query.py", line 1025, in
tryBuiltin
    result = pred.evalObj(subj, queue, bindings.copy(), proof,
self.query)
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/term.py", line 963, in
evalObj    return
self.store._fromPython(self.evaluateObject(subj.value()))
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/cwm_math.py", line 122,
in evaluateObject
    if len(subj_py) == 2: return
numeric(subj_py[0]).__truediv__(numeric(subj_py[1]))
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/decimal.py", line 390, in
__truediv__
    return self.__div__(other)
  File "/home/connolly/w3ccvs/WWW/2000/10/swap/decimal.py", line 152, in
__div__
    while self.magnitude <  self.__class__._limit + other.magnitude +
int(log10(other)):
AttributeError: 'float' object has no attribute 'magnitude'


-- 
Dan Connolly, W3C http://www.w3.org/People/Connolly/

Received on Monday, 16 August 2004 21:34:20 UTC