W3C home > Mailing lists > Public > public-cwm-bugs@w3.org > August 2004

float/decimal mix-up when doing financial calculations

From: Dan Connolly <connolly@w3.org>
Date: Mon, 16 Aug 2004 16:34:48 -0500
To: public-cwm-bugs@w3.org
Message-Id: <1092692088.4845.2289.camel@dirk>
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/


@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix k: <http://opencyc.sourceforge.net/daml/cyc.daml#>.
@prefix m: <http://www.w3.org/2000/10/swap/pim/currency@@#>.
@prefix qif: <http://www.w3.org/2000/10/swap/pim/qif#> .
@prefix xsdt: <http://www.w3.org/2001/XMLSchema#>.
@prefix time: <http://www.w3.org/2000/10/swap/time#> .

@prefix : <#>.


:exch1     k:startingDate  [
                 xsdt:date  "2004-08-08" ];
             m:buyCurrency m:USD;
             m:sellCurrency m:CAD.

{ ?X is math:quotient of ("2.3" "1.2") } => { :exch1 m:rate ?X }.

:priceCAD m:priceCurrency m:CAD.
qif:amount m:priceCurrency m:USD.


:trx :priceCAD "12.43";
             k:startingDate  [
                 xsdt:date  "2004-08-12" ] .


{
  ?P m:priceCurrency ?FOREIGN.
  qif:amount m:priceCurrency ?NATIVE.
  ?EXCH m:sellCurrency ?FOREIGN; m:buyCurrency ?NATIVE; m:rate ?RATE;
     k:startingDate [ xsdt:date [ time:year ?Y; time:month ?M ]].

  ?TRX ?P ?QTY;
     k:startingDate [ xsdt:date [ time:year ?Y; time:month ?M ]].

  (?QTY ?RATE) math:quotient ?Q2.
} => { ?TRX qif:amount ?Q2 }.
Received on Monday, 16 August 2004 21:34:20 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 19:52:00 UTC