This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Fri May 28, 2004 7:55 pm
how can i do powers without having expr pow(x,y) using scientific notifications cause i am working with huge figurs and it must be accurant
Code: Select all
proc pow {e arg} {
for {set i 0} {$i <= $e} {incr i} {
if {[info exists expr]} {
set expr [expr $expr*$arg]
} else {
set expr 1
}
}
return $expr
}
i got this but it isn't able to handle big numbers ..
XplaiN but think of me as stupid
spock
Master
Posts: 319 Joined: Thu Dec 12, 2002 8:40 pm
Post
by spock » Sat May 29, 2004 9:32 am
i would consider using bc instead of tcl for this. large numbers should be no problem.
$ echo 5^100 | bc
7888609052210118054117285652827862296732064351090230047702789306640625
photon?
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Sat May 29, 2004 10:00 am
From the expr manpage entry:
The global variable tcl_precision determines the number of significant digits that are retained when floating values are converted to strings (except that trailing zeroes are omitted). If tcl_precision is unset then 6 digits of precision are used. To retain all of the significant bits of an IEEE floating-point number set tcl_precision to 17; if a value is converted to string with 17 digits of precision and then converted back to binary for some later calculation, the resulting binary value is guaranteed to be identical to the original one.
Also see:
http://wiki.tcl.tk/683
^- So from the routines there, you can construct your pow function as such:
Code: Select all
proc pow {num pow} {
set b [tolist 1]
set num [tolist $num]
for {set i 0} {$i < $pow} {incr i} {
set b [multa $b $num]
}
fromlist $b
}
% pow 2 4
16
% pow 14 20
83668255425284801560576
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 29, 2004 10:54 am
hmm is it a lib i should load or .. cause those cmds do not exist (tolist, ..) or should i copy the procs from that page ..
hmm what i mean is is that a lib ..?
XplaiN but think of me as stupid
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Sat May 29, 2004 11:13 am
Did you actually read that page? You would have answered your own question and saved us both time...
<snip>
^- So from the routines there , you can construct your pow function as such
<snip>
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 29, 2004 11:14 am
yes most of it anyway but i am not that good with technical english words ..
XplaiN but think of me as stupid
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 29, 2004 11:14 am
oh ok sorry
XplaiN but think of me as stupid
strikelight
Owner
Posts: 708 Joined: Mon Oct 07, 2002 10:39 am
Contact:
Post
by strikelight » Sat May 29, 2004 11:15 am
Even still, assumedly, you know Tcl, and can see the procs there matching the commands that you know don't exist in stock Tcl language...
Ofloo
Owner
Posts: 953 Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:
Post
by Ofloo » Sat May 29, 2004 11:18 am
yes ur right but i just wanted to know if there was a lib for this or that i just could use those procs .. cause its in a lib (tcllib) then it would be stupid to copy it then i just could do package require
i always wana make sur sorry for the stupid questions
XplaiN but think of me as stupid