Re: question prompted by "Re: Tcl 8.5 sometimes produces numbers with long fractional parts"



At Fri, 20 Mar 2009 15:21:11 -0500 Richard Owlett <rowlett@xxxxxxxxxxxxx> wrote:


Robert Heller wrote:
At Fri, 20 Mar 2009 11:35:17 -0700 (PDT) Arjen Markus <arjen.markus@xxxxxxxxxx> wrote:


Hello,

if you compute 0.2*3 in Tcl 8.5 the result is:

% expr {0.2*3}
0.6000000000000001

rather than the 0.6 I would have liked to get.

It is annoying in the context of Plotchart where sometimes you get
labels like this:
0.0, 0.2, 0.4, 0.6000000000000001, 0.8, 1.0

I can solve it via tcl_precision, but it remains a bit annoying. (I
guess there is no
easy numerical solution for this ...)

Regards,

Arjen


The above is *typical* of digital *binary* floating point arithmetic.
Don't ever expect that arithmetic involving nice 'rational' *decimal*
numbers like .2 or 3 to result in nice 'rational' *binary* numbers.
(.1, in binary is about as bad as 1/3 is as a decimal fraction).
Yes, you either need to set tcl_precision to some value that makes
sense OR use [format {%x.yf} $x] (with suitable values for x and y) to
generate the *textual* labels for your plots. I would most definately
recomend that for labels of a plot, you should always use the format
command, as this will insure that the labels are notionally consistent,
no matter what their values might be. And there are various 'tricks' to
generate the format string itself, based on the data range (hint: you
can use format itself to generate the format string).


Back in the "Good Old Days" when the 8085 was the latest thing.

Some microprocessors addressed this issue by having instructions which
did BCD arithmetic.

The BCD arithmetic ops in the 8085 was a holdover from the BCD
arithmetic ops in the 4004 and 4040. The *original* 'microprocessor'
(the 4004) was developed to be the heart of a line of multifunction
calculators, so it had instructions that were optimal for that
application. Some of the early 8-bit microprocessors also had some
similar instructions, for much the same purposes (and for things like
quick and easy implementation of simple-minded embeded functions -- eg
toaster ovens and the like).

Modern general purpose 32-bit and 64-bit processors don't bother with
these sorts of instructions. Between modern compilers and their
run-time-libraries (eg [sf]printf() and [sf]scanf()), etc.) there is
little advantage.


Does TCL support a similar solution?
I did a quick search for "BCD" and 'arbitrary precision' {which in TCL
doesn't seem to reference what I was thinking of} - found nothing.

I don't think it has any native "BCD" ALU instructions. Not that it
would not be possible to implement such, but it would not really save
any CPU cycles -- it would be faster to use normal *binary* integer and
floating point math and then use format to convert to fixed width
decimal string representation.

Generally, 'arbitrary precision' (aka bignums) is something else.



--
Robert Heller -- 978-544-6933
Deepwoods Software -- Download the Model Railroad System
http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows
heller@xxxxxxxxxxxx -- http://www.deepsoft.com/ModelRailroadSystem/

.



Relevant Pages

  • question prompted by "Re: Tcl 8.5 sometimes produces numbers with long fractional parts"
    ... generate the *textual* labels for your plots. ... generate the format string itself, based on the data range (hint: ... Does TCL support a similar solution? ...
    (comp.lang.tcl)
  • Re: hdtv format questions
    ... his customary fee for all techno work is a six pack. ... don't have the instructions, download the manual from the SA web site. ... just switched from Dish Network to BrightHouse ... digital and analog stations there is no "good" screen format. ...
    (alt.tv.tech.hdtv)
  • Re: Placing Text On .tiff File Format Picture
    ... yes, you're right, I forgot the "Format text box" subentry in the contextual ... Your instructions worked and I've completed my project to my liking. ... right-click the border of your text box. ... There is no smooth movement, and being able to stop *anywhere*. ...
    (microsoft.public.mac.office.word)
  • Re: Maxtor Backup failure - ping Anna! (about Acronis)
    ... formatted after I remove the Maxtor backup software that came on it? ... format the drive. ... The ATI program does indeed create clones. ... Did you see the step-by-step instructions I posted to Barbara in this thread ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Word Data Merge Query to Address Book Doesnt Display all Categories
    ... I did follow the instruction but after step 4, Create Labels, I got different screens than the instructions. ... In the Mail Merge Manager palette, click Create New, and then click Labels. ... In the filter recipients section, ...
    (microsoft.public.mac.office.word)

Loading