Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Value for tcl_precision

62 views
Skip to first unread message

Cecil Westerhof

unread,
Nov 19, 2017, 6:59:07 AM11/19/17
to
I just started with TCL. I understood that the default value for
tcl_precision should be 12, but on my system it is 0. Which turns out
to do the same as 17, which is also the highest value I can use.

Is this the way it should be?

I am using 8.6.6 on Debian 9.2.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

h.ol...@geon.nl

unread,
Nov 19, 2017, 9:13:09 AM11/19/17
to
From the man (https://www.tcl.tk/man/tcl/TclCmd/tclvars.htm):

"The default value of 0 is special, meaning that Tcl should convert numbers using as few digits as possible while still distinguishing any floating point number from its nearest neighbours. It differs from using an arbitrarily high value for tcl_precision in that an inexact number like 1.4 will convert as 1.4 rather than 1.3999999999999999 even though the latter is nearer to the exact value of the binary number."

Harm

Rich

unread,
Nov 19, 2017, 10:37:29 AM11/19/17
to
Further from the same man page, and the *most important* quote for this
topic (the emphasis below is also in the manpage):

*Applications should not change this value;* it is provided for
compatibility with legacy code.

Since the OP says they just started Tcl, the best advice is to follow
the above sentence in the manpage. Ignore tcl_precision entirely, do
not change it.

If the OP wants a floating point number converted to a string with some
specific fixed number of digits, use the [format] command and the
various floating point formatting substitutions to perform the
conversion.

Cecil Westerhof

unread,
Nov 21, 2017, 4:59:06 AM11/21/17
to
Rich <ri...@example.invalid> writes:

> h.ol...@geon.nl wrote:
>> On Sunday, November 19, 2017 at 12:59:07 PM UTC+1, Cecil Westerhof wrote:
>>> I just started with TCL. I understood that the default value for
>>> tcl_precision should be 12, but on my system it is 0. Which turns
>>> out to do the same as 17, which is also the highest value I can use.
>>>
>>> Is this the way it should be?
>>>
>>> I am using 8.6.6 on Debian 9.2.
>>>
>>> --
>>> Cecil Westerhof
>>> Senior Software Engineer
>>> LinkedIn: http://www.linkedin.com/in/cecilwesterhof
>>
>> From the man (https://www.tcl.tk/man/tcl/TclCmd/tclvars.htm):
>>
>> "The default value of 0 is special, meaning that Tcl should convert
>> numbers using as few digits as possible while still distinguishing
>> any floating point number from its nearest neighbours. It differs
>> from using an arbitrarily high value for tcl_precision in that an
>> inexact number like 1.4 will convert as 1.4 rather than
>> 1.3999999999999999 even though the latter is nearer to the exact
>> value of the binary number."
>
> Further from the same man page, and the *most important* quote for this
> topic (the emphasis below is also in the manpage):
>
> *Applications should not change this value;* it is provided for
> compatibility with legacy code.

Aah, then the tutorial I got is not a very good one. It said it was 12
and one of the suggestions was to change it. I will not do it then.


> Since the OP says they just started Tcl, the best advice is to follow
> the above sentence in the manpage. Ignore tcl_precision entirely, do
> not change it.
>
> If the OP wants a floating point number converted to a string with some
> specific fixed number of digits, use the [format] command and the
> various floating point formatting substitutions to perform the
> conversion.

I will do it like that then.

Arjen Markus

unread,
Nov 21, 2017, 6:54:42 AM11/21/17
to
On Tuesday, November 21, 2017 at 10:59:06 AM UTC+1, Cecil Westerhof wrote:

> >
> > Further from the same man page, and the *most important* quote for this
> > topic (the emphasis below is also in the manpage):
> >
> > *Applications should not change this value;* it is provided for
> > compatibility with legacy code.
>
> Aah, then the tutorial I got is not a very good one. It said it was 12
> and one of the suggestions was to change it. I will not do it then.
>

Hm, which tutorial was that then? The tcl_precision variable has been deprecated for such use for many years.

Regards,

Arjen

Cecil Westerhof

unread,
Nov 21, 2017, 7:44:07 AM11/21/17
to
For one the TCL/TK tutorial from TutorialsPoint (18-19). It is from
2015, but there where some other problems with it also. So maybe I
should not use tutorials from TutorialsPoint.

Gerald Lester

unread,
Nov 21, 2017, 9:41:54 AM11/21/17
to
On 11/21/2017 06:22 AM, Cecil Westerhof wrote:
> Arjen Markus <arjen.m...@gmail.com> writes:
>
>> On Tuesday, November 21, 2017 at 10:59:06 AM UTC+1, Cecil Westerhof wrote:
>>
>>>>
>>>> Further from the same man page, and the *most important* quote for this
>>>> topic (the emphasis below is also in the manpage):
>>>>
>>>> *Applications should not change this value;* it is provided for
>>>> compatibility with legacy code.
>>>
>>> Aah, then the tutorial I got is not a very good one. It said it was 12
>>> and one of the suggestions was to change it. I will not do it then.
>>>
>>
>> Hm, which tutorial was that then? The tcl_precision variable has
>> been deprecated for such use for many years.
>
> For one the TCL/TK tutorial from TutorialsPoint (18-19). It is from
> 2015, but there where some other problems with it also. So maybe I
> should not use tutorials from TutorialsPoint.
>

I'd recommend: https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

Although a bunch are also listed on: http://wiki.tcl.tk/1304 with
comments about each.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Rich

unread,
Nov 21, 2017, 11:35:45 AM11/21/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Rich <ri...@example.invalid> writes:
>
>> h.ol...@geon.nl wrote:
>>> On Sunday, November 19, 2017 at 12:59:07 PM UTC+1, Cecil Westerhof wrote:
>>>> I just started with TCL. I understood that the default value for
>>>> tcl_precision should be 12, but on my system it is 0. Which turns
>>>> out to do the same as 17, which is also the highest value I can use.
>>>>
>>>> Is this the way it should be?
>>>>
>>>> I am using 8.6.6 on Debian 9.2.
>>>
>>> From the man (https://www.tcl.tk/man/tcl/TclCmd/tclvars.htm):
>>>
>>> "The default value of 0 is special, meaning that Tcl should convert
>>> numbers using as few digits as possible while still distinguishing
>>> any floating point number from its nearest neighbours. It differs
>>> from using an arbitrarily high value for tcl_precision in that an
>>> inexact number like 1.4 will convert as 1.4 rather than
>>> 1.3999999999999999 even though the latter is nearer to the exact
>>> value of the binary number."
>>
>> Further from the same man page, and the *most important* quote for this
>> topic (the emphasis below is also in the manpage):
>>
>> *Applications should not change this value;* it is provided for
>> compatibility with legacy code.
>
> Aah, then the tutorial I got is not a very good one. It said it was 12
> and one of the suggestions was to change it. I will not do it then.

That is likely a _very old_ tutorial then. It was normal to change
tcl_precision back in the Tcl 7.x days. It has been unnecessary to do
so since 8.0 arrived. The global remains for backwards compatibility
with old code.

Rich

unread,
Nov 21, 2017, 11:37:57 AM11/21/17
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Arjen Markus <arjen.m...@gmail.com> writes:
>
>> On Tuesday, November 21, 2017 at 10:59:06 AM UTC+1, Cecil Westerhof wrote:
>>
>>> >
>>> > Further from the same man page, and the *most important* quote for this
>>> > topic (the emphasis below is also in the manpage):
>>> >
>>> > *Applications should not change this value;* it is provided for
>>> > compatibility with legacy code.
>>>
>>> Aah, then the tutorial I got is not a very good one. It said it was 12
>>> and one of the suggestions was to change it. I will not do it then.
>>>
>>
>> Hm, which tutorial was that then? The tcl_precision variable has
>> been deprecated for such use for many years.
>
> For one the TCL/TK tutorial from TutorialsPoint (18-19). It is from
> 2015, but there where some other problems with it also. So maybe I
> should not use tutorials from TutorialsPoint.

A tutorial written in 2015 (as opposed to written in 1997) that still
recommends toying with tcl_precision (much less even acknowledges its
existence) sounds like a tutorial you would be best suited to avoid.
If the writer is that far behind, what else are they behind on?

Cecil Westerhof

unread,
Nov 21, 2017, 4:14:06 PM11/21/17
to
Gerald Lester <Gerald...@KnG-Consulting.net> writes:

> On 11/21/2017 06:22 AM, Cecil Westerhof wrote:
>> Arjen Markus <arjen.m...@gmail.com> writes:
>>
>>> On Tuesday, November 21, 2017 at 10:59:06 AM UTC+1, Cecil Westerhof wrote:
>>>
>>>>>
>>>>> Further from the same man page, and the *most important* quote for this
>>>>> topic (the emphasis below is also in the manpage):
>>>>>
>>>>> *Applications should not change this value;* it is provided for
>>>>> compatibility with legacy code.
>>>>
>>>> Aah, then the tutorial I got is not a very good one. It said it was 12
>>>> and one of the suggestions was to change it. I will not do it then.
>>>>
>>>
>>> Hm, which tutorial was that then? The tcl_precision variable has
>>> been deprecated for such use for many years.
>>
>> For one the TCL/TK tutorial from TutorialsPoint (18-19). It is from
>> 2015, but there where some other problems with it also. So maybe I
>> should not use tutorials from TutorialsPoint.
>>
>
> I'd recommend: https://www.tcl.tk/man/tcl8.5/tutorial/tcltutorial.html

I am going to look into that. Thank you.
0 new messages