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

data type conversion in Tcl

20 views
Skip to first unread message

maura.m...@gmail.com

unread,
Apr 27, 2006, 6:48:56 AM4/27/06
to
In C language it is possible to convert a data type by explicit
assignment or by casting.
Fore instance:
int Num;
float Rnum;

Rnum = num;
Rnum = (float) num;

Is it ;possible to do the same in Tcl language ?
I have an integer value but it's too big to e represented as an
integer.
However, I've just found out Tcl has no problem at representing the
float
counterpart.
Is it possible to convert integers into real numbers with Tcl ?
How ?

Thank you so much,
Maura

Arjen Markus

unread,
Apr 27, 2006, 7:03:04 AM4/27/06
to
Yes:

expr {wide($num)} converts to a very large integer
expr{double($num)} converts to a double-precision floating-point number

Regards,

Arjen

Cameron Laird

unread,
Apr 27, 2006, 9:08:02 AM4/27/06
to
In article <1146135784.6...@v46g2000cwv.googlegroups.com>,

Arjen Markus <arjen....@wldelft.nl> wrote:
>Yes:
>
>expr {wide($num)} converts to a very large integer
>expr{double($num)} converts to a double-precision floating-point number
.
.
.
Yes and no.

I think I now understand what the original poster wants, and I'll
post on that later in the day. Notice, though, Arjen, that
% expr wide(111111111111111111111111111111111111)
integer value too large to represent
% expr double(11111111111111111111111111111111111)
integer value too large to represent

Ulrich Schöbel

unread,
Apr 27, 2006, 9:20:37 AM4/27/06
to

How about

set i 111111111111111111111111111111111111
set i $i.0
expr {$i}

Cheers

Ulrich


MartinLemburg@UGS

unread,
Apr 27, 2006, 10:01:20 AM4/27/06
to
Hi Ulrich,

isn't there another possibility?

Martin

Donal K. Fellows

unread,
Apr 27, 2006, 10:42:26 AM4/27/06
to
Cameron Laird wrote:
>Notice, though, Arjen, that
> % expr wide(111111111111111111111111111111111111)
> integer value too large to represent
> % expr double(11111111111111111111111111111111111)
> integer value too large to represent

But also notice:
% expr wide(111111111111111111111111111111111111)
-2663765922256490041
% expr double(11111111111111111111111111111111111)
1.111111111111111e+34
% expr entier(11111111111111111111111111111111111)
11111111111111111111111111111111111
% info patch
8.5a4

Donal.

MartinLemburg@UGS

unread,
Apr 27, 2006, 10:48:50 AM4/27/06
to
Hi Donal,

the examples of yours don't work with my tclkit(sh) 8.5a4.

There is always the error message "integer value too large to
represent".

Do I miss a thing?

Cameron Laird

unread,
Apr 27, 2006, 11:08:01 AM4/27/06
to
In article <1146134936.2...@i39g2000cwa.googlegroups.com>,
.
.
.
There are several problems with what you've written here.
For now, though, please put this at the beginning of your
definition:
proc format_vis { num ticksfmt } {

# Accomodate integer overflows.
if {![string match *.* $num]} {
append num .
}
set intfmt "%8.1f"
set floatfmt "%8.4f"
set scienfmt "%8.2e"
...
Try this, and report whether it achieves what you're after.
With that in hand, we can straighten out your other questions
in relative leisure.

Neil Madden

unread,
Apr 27, 2006, 2:59:58 PM4/27/06
to

I can't remember when exactly the bignum support went in, so perhaps you
have an 8.5a4 pre-TIP 237.

On this subject, I notice some (all?) Scheme implementation allow you to
require individual SRFIs. Perhaps we could do the same with TIPs?

package require tip-237 1.0

or something similar. Or we could just live with the fact that 8.5 is in
development and so the precise feature set available in any particular
8.5 tclsh is variable.

-- Neil

Donal K. Fellows

unread,
Apr 27, 2006, 5:07:08 PM4/27/06
to
Martin Lemburg wrote:
> the examples of yours don't work with my tclkit(sh) 8.5a4.

Well, it works for me with the 8.5a4 release revisions. Time to upgrade!

Donal.

0 new messages