INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

tcl 8.5 floating point operation

tcl 8.5 floating point operation

(OP)
Hi I am using tcl 8.5.
When I do division 1.0/1e-9 i get 999999999.9999999 instead of 1e9.
The same operation on tcl 8.4 works fine.
How to get around this problem to get the correct value/


for {set x 0} {$x<20} {incr x} { puts "$x [expr 1/1e-$x]"}
-----------
OUTPUT
-----------
0 1.0
1 10.0
2 100.0
3 1000.0
4 10000.0
5 99999.99999999999
6 1000000.0
7 10000000.0
8 100000000.0
9 999999999.9999999
10 10000000000.0
11 100000000000.0
12 1000000000000.0
13 10000000000000.0
14 100000000000000.0
15 999999999999999.9
16 10000000000000000.0
17 1e+17
18 9.999999999999999e+17
19 1e+19

RE: tcl 8.5 floating point operation

Use format, for example:

CODE

for {set x 0} {$x<20} {incr x} {
puts [format "%2d %g" $x [expr 1/1e-$x]]
}
outputs

CODE

00 1
01 10
02 100
03 1000
04 10000
05 100000
06 1e+006
07 1e+007
08 1e+008
09 1e+009
10 1e+010
11 1e+011
12 1e+012
13 1e+013
14 1e+014
15 1e+015
16 1e+016
17 1e+017
18 1e+018
19 1e+019

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close