Menu

#292 nint(x) works in independent sources and expressions but not recognised in B sources.

v1.0 (example)
closed-fixed
nobody
None
5
2014-09-20
2014-09-18
No

In Ngspice 26 from git, it looks like the NINT(x) function (Nearest integer, half integers rounded towards even) function is not recognised when used in dependent (B) sources.

The netlist below illustrates the problem:


  • ngspice nint(x) test jig

.param boo=-2.5

  • ref={NINT(2.5)}

V1 IN GND {0.5} SIN(0 4.1 1k)
V2 REF1 GND {ref}
V3 REF2 GND {NINT(boo)}

  • Uncommenting any of the 3 lines below generates an error report:
    B1 NINT_FUNCTION1 GND V=NINT(2)
    B2 NINT_FUNCTION2 GND V=NINT(boo)
    *B3 NINT_FUNCTION3 GND V=NINT(V(in))

.TRAN 1u 1m
*.OP

probe V(in) V(ref1) V(ref2) ; V(nint_function1) V(nint_function2) V(nint_function3)

.END


The netlist above runs without errors if the B1 - B3 lines are commented out. Running the netlist with B1, B2 and B3 lines uncommented produces an error report containing this information:

==============================
:
Error: no such function 'nint'
Error: no such function 'nint'
Error: no such function 'nint'
Error on line 24 : b1 nint_function1 0 v= nint ( 2.0000000000e+00 )
parameter value out of range or the wrong type
Error on line 25 : b2 nint_function2 0 v= nint ( -2.50000000000000000e+00 )
parameter value out of range or the wrong type
Error on line 26 : b3 nint_function3 0 v= nint ( v(in) )
parameter value out of range or the wrong type
:
===============================

Many thanks for your attention,

     Andy.

signality.co.uk

Related

Bugs: #292

Discussion

  • marcel hendrix

    marcel hendrix - 2014-09-18

    The ngspice-26 manual does not list nint(x) as a supported function, and
    mentions that nint(x) is allowed in param statements. Therefore the
    signaled behavior is formally not a B-source bug.

    I think numparm is to blame, as:

    ::html
     B1 NINT_FUNCTION1 GND  V=NINT(2)
     B2 NINT_FUNCTION2 GND  V=NINT(boo)
     B3 NINT_FUNCTION3 GND  V=NINT(V(in))
    

    should have worked for B1 and B2 ( B1 <- 2, B2 <- 2.5).
    Reason: numparm does not substitute the NINT(<x>) strings. </x>

     
    • Andy Fierman

      Andy Fierman - 2014-09-18

      nint(x) is defined in the table on page 57 of:

      http://ngspice.sourceforge.net/docs/ngspice-manual.pdf

      However, it is not clear to me exactly what this table is defining: it has
      no title and is not clearly referenced in the text.

      This is the only place that nint(x) is described.

      Does this table refer specifically to functions that can be used only in
      .param statements?

      If so, can they also be used in expressions for independent sources and
      other component values like:

      R1 net1 gnd {nint(5.6)}

      V1 net2 gnd sin(0 1 {nint(2.5k)})

      Coming from using LTspice, I'd expected to find that if a function is
      defined then it would work in any context.

      It would certainly make the user's life much simpler (but not the
      developers!).

      :)

           Andy.
      

      signality.co.uk

      On 18 September 2014 18:31, marcel hendrix mhx_at_sf@users.sf.net wrote:

      The ngspice-26 manual does not list nint(x) as a supported function, and
      mentions that nint(x) is allowed in param statements. Therefore the
      signaled behavior is formally not a B-source bug.

      I think numparm is to blame, as:

      B1 NINT_FUNCTION1 GND V=NINT(2)
      B2 NINT_FUNCTION2 GND V=NINT(boo)
      B3 NINT_FUNCTION3 GND V=NINT(V(in))

      should have worked for B1 and B2 ( B1 <- 2, B2 <- 2.5).
      Reason: numparm does not substitute the NINT(<x>) strings.</x>


      Status: open
      Group: v1.0 (example)
      Created: Thu Sep 18, 2014 12:38 PM UTC by Andy Fierman
      Last Updated: Thu Sep 18, 2014 12:38 PM UTC
      Owner: nobody

      In Ngspice 26 from git, it looks like the NINT(x) function (Nearest
      integer, half integers rounded towards even) function is not recognised
      when used in dependent (B) sources.

      The netlist below illustrates the problem:

      • ngspice nint(x) test jig

      .param boo=-2.5
      + ref={NINT(2.5)}

      V1 IN GND {0.5} SIN(0 4.1 1k)
      V2 REF1 GND {ref}
      V3 REF2 GND {NINT(boo)}

      • Uncommenting any of the 3 lines below generates an error report:

      B1 NINT_FUNCTION1 GND V=NINT(2) B2 NINT_FUNCTION2 GND V=NINT(boo)
      *B3 NINT_FUNCTION3 GND V=NINT(V(in))

      .TRAN 1u 1m
      *.OP

      probe V(in) V(ref1) V(ref2) ; V(nint_function1) V(nint_function2)
      V(nint_function3)

      .END

      The netlist above runs without errors if the B1 - B3 lines are commented
      out. Running the netlist with B1, B2 and B3 lines uncommented produces an
      error report containing this information:

      ==============================
      :
      Error: no such function 'nint'
      Error: no such function 'nint'
      Error: no such function 'nint'
      Error on line 24 : b1 nint_function1 0 v= nint ( 2.0000000000e+00 )
      parameter value out of range or the wrong type
      Error on line 25 : b2 nint_function2 0 v= nint ( -2.50000000000000000e+00 )
      parameter value out of range or the wrong type
      Error on line 26 : b3 nint_function3 0 v= nint ( v(in) )
      parameter value out of range or the wrong type
      :
      ===============================

      Many thanks for your attention,

       Andy.
      

      signality.co.uk

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/ngspice/bugs/292/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #292

      • Andy Fierman

        Andy Fierman - 2014-09-19

        "The ngspice-26 manual does not list nint(x) as a supported function,"

        Not sure that's true now: it was announced as a new feature in the ngspice
        release 26, January 12th, 2014 and is in thesame table on page 57 in the
        stable released manual:

        http://ngspice.sourceforge.net/docs/ngspice26-manual.pdf

        Cheers,

             Andy.
        

        signality.co.uk

        On 18 September 2014 22:33, Andy Fierman andyfierman@signality.co.uk
        wrote:

        nint(x) is defined in the table on page 57 of:

        http://ngspice.sourceforge.net/docs/ngspice-manual.pdf

        However, it is not clear to me exactly what this table is defining: it has
        no title and is not clearly referenced in the text.

        This is the only place that nint(x) is described.

        Does this table refer specifically to functions that can be used only in
        .param statements?

        If so, can they also be used in expressions for independent sources and
        other component values like:

        R1 net1 gnd {nint(5.6)}

        V1 net2 gnd sin(0 1 {nint(2.5k)})

        Coming from using LTspice, I'd expected to find that if a function is
        defined then it would work in any context.

        It would certainly make the user's life much simpler (but not the
        developers!).

        :)

             Andy.
        

        signality.co.uk

        On 18 September 2014 18:31, marcel hendrix mhx_at_sf@users.sf.net wrote:

        The ngspice-26 manual does not list nint(x) as a supported function, and
        mentions that nint(x) is allowed in param statements. Therefore the
        signaled behavior is formally not a B-source bug.

        I think numparm is to blame, as:

        B1 NINT_FUNCTION1 GND V=NINT(2)
        B2 NINT_FUNCTION2 GND V=NINT(boo)
        B3 NINT_FUNCTION3 GND V=NINT(V(in))

        should have worked for B1 and B2 ( B1 <- 2, B2 <- 2.5).
        Reason: numparm does not substitute the NINT(<x>) strings.</x>


        Status: open
        Group: v1.0 (example)
        Created: Thu Sep 18, 2014 12:38 PM UTC by Andy Fierman
        Last Updated: Thu Sep 18, 2014 12:38 PM UTC
        Owner: nobody

        In Ngspice 26 from git, it looks like the NINT(x) function (Nearest
        integer, half integers rounded towards even) function is not recognised
        when used in dependent (B) sources.

        The netlist below illustrates the problem:

        • ngspice nint(x) test jig

        .param boo=-2.5
        + ref={NINT(2.5)}

        V1 IN GND {0.5} SIN(0 4.1 1k)
        V2 REF1 GND {ref}
        V3 REF2 GND {NINT(boo)}

        • Uncommenting any of the 3 lines below generates an error report:

        B1 NINT_FUNCTION1 GND V=NINT(2) B2 NINT_FUNCTION2 GND V=NINT(boo)
        *B3 NINT_FUNCTION3 GND V=NINT(V(in))

        .TRAN 1u 1m
        *.OP

        probe V(in) V(ref1) V(ref2) ; V(nint_function1) V(nint_function2)
        V(nint_function3)

        .END

        The netlist above runs without errors if the B1 - B3 lines are commented
        out. Running the netlist with B1, B2 and B3 lines uncommented produces an
        error report containing this information:

        ==============================
        :
        Error: no such function 'nint'
        Error: no such function 'nint'
        Error: no such function 'nint'
        Error on line 24 : b1 nint_function1 0 v= nint ( 2.0000000000e+00 )
        parameter value out of range or the wrong type
        Error on line 25 : b2 nint_function2 0 v= nint ( -2.50000000000000000e+00
        )
        parameter value out of range or the wrong type
        Error on line 26 : b3 nint_function3 0 v= nint ( v(in) )
        parameter value out of range or the wrong type
        :
        ===============================

        Many thanks for your attention,

         Andy.
        

        signality.co.uk

        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/ngspice/bugs/292/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/

         

        Related

        Bugs: #292

        • marcel hendrix

          marcel hendrix - 2014-09-19

          "The ngspice-26 manual does not list nint(x) as a supported function,"

          Not sure that's true now: it was announced as a new feature in the ngspice
          release 26, January 12th, 2014 and is in the same table on page 57 in the
          stable released manual:

          http://ngspice.sourceforge.net/docs/ngspice26-manual.pdf

          I looked at the release notes, and nint is not for B-sources (note the
          different formulation for pwr). That this is clear to me is probably
          because I am (by now) well aware of the 3 different ngspice parsers.
          (Yes, I believe that they should be transparent.)

          I recommend to retract the bug report for the B-source parser and
          file one for the bug in numparam instead.

          -marcel

           
  • Robert Larice

    Robert Larice - 2014-09-19

    Hello Andy, Marcel,

    Its not a numparm bug, but a missing implementation in the B parser.

    Some time ago, I've put some effort into the numparm parser
    to make some details compatibel to another spice.
    Thats somewhat expressed in the regression test
    tests/regression/parser/xpressn-1.cir
    For example nint() was missing, got implemented, and was then tested there.

    Concerning this (numparm) section, I currently know of the various
    pwr pwrs ^ and ** operators, which need to be polished too.

    I've not cared about the B world at that time.

    Thus, indeed its a bug/missing feature
    and a similiar regression .cir file needs to be written for B too
    (and for .control of course)

    Robert

     

    Last edit: Robert Larice 2014-09-19
  • Robert Larice

    Robert Larice - 2014-09-20

    Hello Andy,

    I've pushed commits to implement nint for 'B' and for '.control'
    A regression test is pushed as well.

    Thanks for the report.
    Robert

     
  • Robert Larice

    Robert Larice - 2014-09-20
    • status: open --> closed-fixed
     
    • Andy Fierman

      Andy Fierman - 2014-09-20

      Robert,

      Many thanks!

      Deep joy.

      Cheers,

           Andy.
      

      signality.co.uk

      On 20 September 2014 16:34, Robert Larice rlar@users.sf.net wrote:

      • status: open --> closed-fixed

      Status: closed-fixed
      Group: v1.0 (example)
      Created: Thu Sep 18, 2014 12:38 PM UTC by Andy Fierman
      Last Updated: Sat Sep 20, 2014 03:33 PM UTC
      Owner: nobody

      In Ngspice 26 from git, it looks like the NINT(x) function (Nearest
      integer, half integers rounded towards even) function is not recognised
      when used in dependent (B) sources.

      The netlist below illustrates the problem:

      • ngspice nint(x) test jig

      .param boo=-2.5
      + ref={NINT(2.5)}

      V1 IN GND {0.5} SIN(0 4.1 1k)
      V2 REF1 GND {ref}
      V3 REF2 GND {NINT(boo)}

      • Uncommenting any of the 3 lines below generates an error report:

      B1 NINT_FUNCTION1 GND V=NINT(2) B2 NINT_FUNCTION2 GND V=NINT(boo)
      *B3 NINT_FUNCTION3 GND V=NINT(V(in))

      .TRAN 1u 1m
      *.OP

      probe V(in) V(ref1) V(ref2) ; V(nint_function1) V(nint_function2)
      V(nint_function3)

      .END

      The netlist above runs without errors if the B1 - B3 lines are commented
      out. Running the netlist with B1, B2 and B3 lines uncommented produces an
      error report containing this information:

      ==============================
      :
      Error: no such function 'nint'
      Error: no such function 'nint'
      Error: no such function 'nint'
      Error on line 24 : b1 nint_function1 0 v= nint ( 2.0000000000e+00 )
      parameter value out of range or the wrong type
      Error on line 25 : b2 nint_function2 0 v= nint ( -2.50000000000000000e+00 )
      parameter value out of range or the wrong type
      Error on line 26 : b3 nint_function3 0 v= nint ( v(in) )
      parameter value out of range or the wrong type
      :
      ===============================

      Many thanks for your attention,

       Andy.
      

      signality.co.uk

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/ngspice/bugs/292/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #292

  • Andy Fierman

    Andy Fierman - 2014-12-19

    Hi,

    If I run the netlist below in ngpsice.com (release 26) then the tilde in:

    ainv1 ~ind outd buff

    inverts the input OK.

    If I remove the tilde so that line becomes:

    ainv1 ind outd buff

    and insert one into:

    aoutbridge1 [~outd] [out] dac

    then that inverts the input OK too.

    However, if I run this in EasyEDA using ngspice from git then the tilde is
    ignored in either location.

    • Is this a bug in ngspice from git?

    This is the example shared on ngspice.com:

    http://www.ngspice.com/index.php?public_circuit=CFHOrs

    and on EasyEDA:

    http://easyeda.com/editor#id=QQ20mH31Z

    Cheers,

         Andy.
    

    signality.co.uk


    • tilde test
      .tran 1.2u 1.2m
      .param
    • tdlo = 20n
    • tdhi = 50n
      **
    • in_low = 0.1
    • in_high = 0.9
    • out_low = 0.1
    • out_high = 0.9
    • out_undef = 0.5
      **
      VCC1 vcc 0 1
      V1 in 0 pulse(0 1 0 10n 10n 500u 1m)
      *
      ainbridge1 [in] [ind] adc1
      .model adc1 adc_bridge(in_low = {in_low} in_high = {in_high})
      *
      ainv1 ~ind outd buff ; inversion using [~ind] works OK
      *
      .model buff d_buffer(rise_delay = {tdhi} fall_delay = {tdlo}
    • input_load = 0.5e-12)
      *
      aoutbridge1 [outd] [out] dac ; inversion using [~outd] works OK here too
      *
      .model dac dac_bridge(out_low = {out_low} out_high = {out_high} out_undef =
      {out_undef}
    • input_load = 5.0e-12 t_rise = 50e-9
    • t_fall = 20e-9)
      *
      *.probe v(in) v(out)
      *
      .end

     

Log in to post a comment.

MongoDB Logo MongoDB