[Swift-user] Re: 1.0 vs 1
Michael Wilde
wilde at mcs.anl.gov
Wed Nov 3 15:37:07 CDT 2010
Marc, the solution here is to say:
string str_modulo = @strcat( int_index, ":1000" );
instead of:
string str_modulo = @strcat( @tostring( int_index ), ":1000" );
Its a handy feature of @strcat() that it coerces its arguments to strings when they are numeric, and does it in the desired way, unlike @tostring().
I am not sure if @tostring() has always behaved this way (ie always formatting as if its argument is a float), or of that was a recent, perhaps undesirable or inadvertent change.
This is the kind of question you should submit to swift-user for general discussion and so other developers can provide advice.
Also, we have a sprintf()-like function that I think is not yet documented, if you need it. I need to find the details on that.
- Mike
----- Original Message -----
> Hi guys,
>
> I'm trying to generate a string whose content should be "0:1000",
> "1:1000", etc...
>
> foreach mod_index in [0:1]
> {
> int int_index = mod_index;
> string str_modulo = @strcat( @tostring( int_index ), ":1000" );
> ...
> }
>
>
> that str_modulo string ends up to contain "0.0:1000", "1.0:1000", etc
>
> I thought it was an int? So the culprit is the tostring function then?
> It is not defined for the int type so it is silently converted into
> float then passed to the tostring function??
>
>
> Very Best,
> Marc.
--
Michael Wilde
Computation Institute, University of Chicago
Mathematics and Computer Science Division
Argonne National Laboratory
More information about the Swift-user
mailing list