This is not actually a problem. 1.38777878078145e-16 is an excellent
approximation to the desired value of zero, and an excellent approximation
is the best you can ever hope for, with finite-precision arithmetic.
You're accumulating round-off error each time you add or subtract 0.1.
You could set PREC to, say, 6, and clients would only show 6 digits
of the result. (I don't know right off if dbpr honors PREC, but it's
just a diagnostic routine, so it won't usually matter.)
Silver wrote:
> hi, all:
>
> I am trying to use the record suggested by Ned Arnold. It's good work when
> increment is 1. but when I change to 0.1, it has a strange problem. the db
> file is like following:
>
> record(ai, "$(user):aiExample") { field(DESC, "Analog input") field(INP,
> "$(user):calcExample.VAL NPP NMS") } record(calc, "$(user):calcExample") {
> field(DESC, "Counter") field(SCAN,"1 second") field(FLNK,
> "$(user):aiExample") field(CALC, "A-B>0?A>=0.9?0.8:A+0.1:A<0.1?0.1:A-0.1")
> field(INPA, "$(user):calcExample.VAL NPP NMS") field(INPB,
> "$(user):calcExample.LA NPP NMS") field(EGU, "Counts") }
>
> Following is dbtr message, we can see when the value change to 0.1, after
> caculation, it's value change to VAL: 1.38777878078145e-16, can anyone give
> some suggestion? thanks a lot in advance.
>
> epics> dbtr tcl:calcExample A: 0.2 ACKS: NO_ALARM ACKT: YES
> ADEL: 0 ALST: 0.1 ASG: B: 0.3 BKPT:
> 0x00 C: 0 CALC: A-B>0?A>=0.9?0.8:A+0.1:A<0.1?0.1:A-0.1
> D: 0 DESC: Counter DISA: 0 DISP: 0
> DISS: NO_ALARM DISV: 1 DTYP: <nil> E: 0
> EGU: Counts EVNT: 0 F: 0 FLNK:DB_LINK tcl:aiExample
> G: 0 H: 0 HHSV: NO_ALARM HIGH: 0 HIHI: 0
> HOPR: 0 HSV: NO_ALARM HYST: 0 I: 0 INPA:DB_LINK
> tcl:calcExample.VAL NPP NMS INPB:DB_LINK tcl:calcExample.LA NPP NMS
> INPC:CONSTANT INPD:CONSTANT INPE:CONSTANT INPF:CONSTANT
> INPG:CONSTANT INPH:CONSTANT INPI:CONSTANT INPJ:CONSTANT
> INPK:CONSTANT INPL:CONSTANT J: 0 K: 0 L:
> 0 LA: 0.2 LALM: 0.1 LB: 0.3 LC: 0
> LCNT: 0 LD: 0 LE: 0 LF: 0 LG: 0
> LH: 0 LI: 0 LJ: 0 LK: 0
> LL: 0 LLSV: NO_ALARM LOLO: 0 LOPR: 0
> LOW: 0 LSV: NO_ALARM MDEL: 0 MLST: 0.1
> NAME: tcl:calcExample NSEV: NO_ALARM NSTA: NO_ALARM
> PACT: 0 PHAS: 0 PINI: NO PREC: 0
> PRIO: LOW PROC: 0 PUTF: 0 RPRO: 0
> SCAN: 1 second SDIS:CONSTANT SEVR: NO_ALARM STAT: NO_ALARM
> TPRO: 0 TSE: 0 TSEL:CONSTANT UDF: 0
> VAL: 0.1 epics> dbtr tcl:calcExample A: 0.1 ACKS: NO_ALARM
> ACKT: YES ADEL: 0 ALST: 1.38777878078145e-16 ASG:
> B: 0.2 BKPT: 0x00 C: 0 CALC: A-B>0?A>=0.9?0.8:A+0.1:A<0.1?0.1:A-0.1
> D: 0 DESC: Counter DISA: 0 DISP: 0 DISS:
> NO_ALARM DISV: 1 DTYP: <nil> E: 0 EGU:
> Counts EVNT: 0 F: 0 FLNK:DB_LINK tcl:aiExample
> G: 0 H: 0 HHSV: NO_ALARM HIGH: 0
> HIHI: 0 HOPR: 0 HSV: NO_ALARM HYST: 0
> I: 0 INPA:DB_LINK tcl:calcExample.VAL NPP NMS
> INPB:DB_LINK tcl:calcExample.LA NPP NMS INPC:CONSTANT INPD:CONSTANT
> INPE:CONSTANT INPF:CONSTANT INPG:CONSTANT INPH:CONSTANT
> INPI:CONSTANT INPJ:CONSTANT INPK:CONSTANT INPL:CONSTANT
> J: 0 K: 0 L: 0 LA: 0.1
> LALM: 1.38777878078145e-16 LB: 0.2 LC: 0
> LCNT: 0 LD: 0 LE: 0 LF: 0
> LG: 0 LH: 0 LI: 0 LJ: 0
> LK: 0 LL: 0 LLSV: NO_ALARM LOLO: 0
> LOPR: 0 LOW: 0 LSV: NO_ALARM MDEL: 0
> MLST: 1.38777878078145e-16 NAME: tcl:calcExample
> NSEV: NO_ALARM NSTA: NO_ALARM PACT: 0 PHAS: 0
> PINI: NO PREC: 0 PRIO: LOW PROC: 0
> PUTF: 0 RPRO: 0 SCAN: 1 second SDIS:CONSTANT
> SEVR: NO_ALARM STAT: NO_ALARM TPRO: 0 TSE: 0
> TSEL:CONSTANT UDF: 0 VAL: 1.38777878078145e-16
> epics> dbtr tcl:calcExample A: 1.38777878078145e-16 ACKS:
> NO_ALARM ACKT: YES ADEL: 0 ALST: 0.1 ASG:
> B: 0.1 BKPT: 0x00 C: 0 CALC: A-B>0?A>=0.9?0.8:A+0.1:A<0.1?0.1:A-0.1
> D: 0 DESC: Counter DISA: 0 DISP: 0 DISS:
> NO_ALARM DISV: 1 DTYP: <nil> E: 0 EGU:
> Counts EVNT: 0 F: 0 FLNK:DB_LINK tcl:aiExample
> G: 0 H: 0 HHSV: NO_ALARM HIGH: 0
> HIHI: 0 HOPR: 0 HSV: NO_ALARM HYST: 0
> I: 0 INPA:DB_LINK tcl:calcExample.VAL NPP NMS
> INPB:DB_LINK tcl:calcExample.LA NPP NMS INPC:CONSTANT INPD:CONSTANT
> INPE:CONSTANT INPF:CONSTANT INPG:CONSTANT INPH:CONSTANT
> INPI:CONSTANT INPJ:CONSTANT INPK:CONSTANT INPL:CONSTANT
> J: 0 K: 0 L: 0 LA: 1.38777878078145e-16
> LALM: 0.1 LB: 0.1 LC: 0 LCNT: 0 LD: 0
> LE: 0 LF: 0 LG: 0 LH: 0 LI: 0
> LJ: 0 LK: 0 LL: 0 LLSV: NO_ALARM
> LOLO: 0 LOPR: 0 LOW: 0 LSV: NO_ALARM
> MDEL: 0 MLST: 0.1 NAME: tcl:calcExample
> NSEV: NO_ALARM NSTA: NO_ALARM PACT: 0 PHAS: 0
> PINI: NO PREC: 0 PRIO: LOW PROC: 0
> PUTF: 0 RPRO: 0 SCAN: 1 second SDIS:CONSTANT
> SEVR: NO_ALARM STAT: NO_ALARM TPRO: 0 TSE: 0
> TSEL:CONSTANT UDF: 0 VAL: 0.1 epics>
>
> Best regards Geyang 2008-11-23
>
>
--
Tim Mooney ([email protected]) (630)252-5417
Beamline Controls & Data Acquisition Group
Advanced Photon Source, Argonne National Lab.
- Replies:
- Re: A bug of calc record? Dirk Zimoch
- References:
- A bug of calc record? Silver
- Navigate by Date:
- Prev:
A bug of calc record? Silver
- Next:
Re: Working with sequencer Benjamin Franksen
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
<2008>
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
A bug of calc record? Silver
- Next:
Re: A bug of calc record? Dirk Zimoch
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
<2008>
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|