String>>sprintfWith: with float argument

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

String>>sprintfWith: with float argument

Dmitry Zamotkin-3
Hello!

Try to evaluate:

'%10.2lf' sprintfWith: 12345.678 " or "
'%10.2f' sprintfWith: 12345.678

But first line is rightly, I think, as float in Dolphin Smalltalk is double
precision. After evaluating I hanged Windows 98 and receive '      0.00'
under Windows 2000 Server.

I suspect that it's bug...

--
Dmitry Zamotkin


Reply | Threaded
Open this post in threaded view
|

Re: String>>sprintfWith: with float argument

Ian Bartholomew-4
Dmitry,

> I suspect that it's bug...

This is only half an answer but it might save you wasting time (if it's half
right of course <g>) until OA reply.

In Dolphin V3 and earlier the C runtime library's "sprintf" function was
used for Dolphins equivalent sprintfWith:X methods. Part of that interface
was the following method - note the last bit of the comment

~-~-~-~-
CRTLibrary>>sprintf: buffer format: format with: arg1 with: arg2 with: arg3
    "Private - Write data formatted by the format string into the buffer.
    N.B. sprintf() is not a very safe function. It is not type safe and it
    is possible for a mismatch between the format string and the
    arguments to result in a GPF or stack corruption.
    The arguments can be either SmallIntegers or byte objects (e.g. Strings)
    but not Floats. LargeIntegers will not work correctly with this
    definition either, if one is attempting to pass their value."

    <cdecl: sdword sprintf lpvoid lpstr lpvoid lpvoid lpvoid>
    ^self invalidCall
~-~-~-~-

In Dolphin4 OA stopped using the sprintf api and started using the _snprintf
C RTL function [1] for it's sprintfWith: family of methods. In the process
of the changeover the equivalent of the above (unused) method, and it's
comment, disappeared.

 From your bug report I would guess that the above comment still applies but
is just not documented in the image any longer - a bug in itself I suppose.

Regards
    Ian

[1] I haven't got any C RTL documentation and MSDN is no help so I have no
idea of the difference between sprintf and _snprintf in the library -
although it just looks like the latter allows a maximum buffer size
specification?.


Reply | Threaded
Open this post in threaded view
|

Re: String>>sprintfWith: with float argument

Ian Bartholomew-4
In reply to this post by Dmitry Zamotkin-3
Dmitry,

> I suspect that it's bug...

This is only half an answer but it might save you wasting time (if it's half
right of course <g>) until OA reply.

In Dolphin V3 and earlier the C runtime library's "sprintf" function was
used for Dolphins equivalent sprintfWith:X methods. Part of that interface
was the following method - note the last bit of the comment

~-~-~-~-
CRTLibrary>>sprintf: buffer format: format with: arg1 with: arg2 with: arg3
    "Private - Write data formatted by the format string into the buffer.
    N.B. sprintf() is not a very safe function. It is not type safe and it
    is possible for a mismatch between the format string and the
    arguments to result in a GPF or stack corruption.
    The arguments can be either SmallIntegers or byte objects (e.g. Strings)
    but not Floats. LargeIntegers will not work correctly with this
    definition either, if one is attempting to pass their value."

    <cdecl: sdword sprintf lpvoid lpstr lpvoid lpvoid lpvoid>
    ^self invalidCall
~-~-~-~-

In Dolphin4 OA stopped using the sprintf api and started using the _snprintf
C RTL function [1] for it's sprintfWith: family of methods. In the process
of the changeover the equivalent of the above (unused) method, and it's
comment, disappeared.

>From your bug report I would guess that the above comment still applies but
is just not documented in the image any longer - a bug in itself I suppose.

Regards
    Ian

[1] I haven't got any C RTL documentation and MSDN is no help so I have no
idea of the difference between sprintf and _snprintf in the library -
although it just looks like the latter allows a maximum buffer size
specification?.