• Tcl maths

    From Shaun Kulesa@21:1/5 to All on Mon Mar 13 14:01:31 2023
    I personally don't really like the state of Tcl maths.

    Is this a shared opinion?

    Should we discuss it in the meetup?

    An example would be that 4/3 returns 1 whereas 4/3.0 returns 1.33.

    Thanks.

    Shaun Kulesa

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Shaun Kulesa on Tue Mar 14 07:38:42 2023
    On Monday, March 13, 2023 at 10:01:35 PM UTC+1, Shaun Kulesa wrote:
    I personally don't really like the state of Tcl maths.

    Is this a shared opinion?

    Should we discuss it in the meetup?

    An example would be that 4/3 returns 1 whereas 4/3.0 returns 1.33.

    Thanks.

    Shaun Kulesa

    Can you be more specific? The example you give is a very common pattern among programming languages: you are dividing one integer by another and the result is again an integer. If that is not what you expect you must make it explicitly that you require a
    floating-point answer. Mind you, floating-point numbers have their own set of rules that may surprise and annoy.

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Shaun Kulesa@21:1/5 to All on Tue Mar 14 08:17:10 2023
    Alright you are correct about the division as it does that in C and Java, I must of gotten too familiar with python as If you do print(4/3) in python it will return 1.33.

    Some of my other points are that using expr is silly enough, but the syntax is completely different to the Tcl syntax.

    The functions such as pow use () and commas which is like other languages such as java and python, not Tcl.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Shaun Kulesa on Tue Mar 14 19:10:22 2023
    Shaun Kulesa <shaunkulesa@gmail.com> wrote:
    Some of my other points are that using expr is silly enough, but the
    syntax is completely different to the Tcl syntax.

    The functions such as pow use () and commas which is like other
    languages such as java and python, not Tcl.

    If you want a pure tcl syntax then do:

    namespace path {::tcl::mathop ::tcl::mathfunc}

    in your code, and you get 'Tcl syntax' math:

    $ rlwrap tclsh
    % namespace path {::tcl::mathop ::tcl::mathfunc}
    % set a [+ 3 [* 4 8]]
    35
    % set b [pow 2 8]
    256.0
    %

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to Shaun Kulesa on Tue Mar 14 14:04:56 2023
    On Tuesday, March 14, 2023 at 10:17:15 AM UTC-5, Shaun Kulesa wrote:
    Alright you are correct about the division as it does that in C and Java, I must of gotten too familiar with python as If you do print(4/3) in python it will return 1.33.

    Some of my other points are that using expr is silly enough, but the syntax is completely different to the Tcl syntax.

    The functions such as pow use () and commas which is like other languages such as java and python, not Tcl.

    It is a common mistake to assume that Tcl is like any other programming language. It is not. The language definition is more simplistic. Behavior(s) is(are) defined by the command(s), not by Tcl. This may sound strange, but once you see it, it will
    become clear. Start by (re)reading the Tcl man page (https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm). Note that there is no definition of an "expression". This is by design.

    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)