Dynamic formatting - OS2

This is a discussion on Dynamic formatting - OS2 ; Is there a standard PM dialog available to adjust a number? I forgot the name of the type of dialog in English, but I mean the one with a small up and down "arrow" at the right hand side. Up ...

+ Reply to Thread
Results 1 to 14 of 14

Thread: Dynamic formatting

  1. Dynamic formatting


    Is there a standard PM dialog available to adjust a number? I forgot the
    name of the type of dialog in English, but I mean the one with a small up
    and down "arrow" at the right hand side. Up increases the number, down
    decreases it. The number can (always?) be entered manually too.

    Apart form that, a user can select a number formatting of - let's day -
    5 digits (xxxxX.XX) before the decimal separator instead of 3 (xxX.xx).
    Is there a standard way to use a "dynamic" format, e.g. printf("%5d");
    instead of the default printf("%3d");? I guess there's no special trick
    for that, but OTOH I've seen apps which follow printf() closely using
    a kind of external template.

    Finally, is there a way to specify the precision of a float? I'm getting
    different results with REXX and C, and assume REXX is the winner. Can I
    set the "NUMERIC DIGITS" or something like that somehow, or should I
    avoid the difference by improving my data processing (which is possible
    in this case, just the average I'm using has to be a float instead of each
    value to be averaged).



    ---

  2. Re: Dynamic formatting

    On Sun, 11 Dec 2005 06:41:58 UTC, spamgate@hotmai1.com (ML) wrote:
    Hi,

    > Is there a standard PM dialog available to adjust a number?


    No, not as far as I know.
    I think there are standard ones for messages and filedialogs only.

    For anything more complicated you need to define a dialog layout
    yourself using a resource-file. (can be created with dialog editor).

    >I forgot the name of the type of dialog in English, but I mean the one with a small up
    > and down "arrow" at the right hand side. Up increases the number, down
    > decreases it. The number can (always?) be entered manually too.


    That would be a "spinbox" which is a PM control I think ...
    AFAIK, there are variants with and without an entryfield.


    > Apart form that, a user can select a number formatting of - let's day -
    > 5 digits (xxxxX.XX) before the decimal separator instead of 3 (xxX.xx).
    > Is there a standard way to use a "dynamic" format, e.g. printf("%5d");
    > instead of the default printf("%3d");? I guess there's no special trick
    > for that, but OTOH I've seen apps which follow printf() closely using
    > a kind of external template.


    That would have to be implemented by you.
    There may be (windowing) toolkits like WxWidgets that offer
    a lot of such possibilities though ...

    > Finally, is there a way to specify the precision of a float? I'm getting
    > different results with REXX and C, and assume REXX is the winner. Can I
    > set the "NUMERIC DIGITS" or something like that somehow,


    Yes, but there are only two choices:

    1) Use a 'float' like you do, that will give about 6 digits precision
    2) Use a 'double' to get, well double of that, about 12 digits :-)

    So the difference is in the 'C' variable type you use.
    Many functions in the runtime library can also work with doubles.

    To use it with printf/scanf you use a %lf instead of %f
    (aka 'long float' or 'large float')

    >or should I
    > avoid the difference by improving my data processing (which is possible
    > in this case, just the average I'm using has to be a float instead of each
    > value to be averaged).


    Maybe that too, but using a 'double' maybe enough :-)

    REXX uses a floating-point format with a huge possible
    number of digits, not easy to do in plain 'C'.

    Regards, JvW

    --
    Jan van Wijk; Author of DFSee: http://www.dfsee.com

  3. Re: Dynamic formatting

    There is a "spinblock" control but I'm not sure if it's in the
    standard PM library or if it was one of the IBM classes in the IOC
    library. I don't remember much about the format functionality - I
    always used it with intergers or a percentage.

    On Sun, 11 Dec 2005 06:41:58 UTC spamgate@hotmai1.com (ML) wrote:

    >
    > Is there a standard PM dialog available to adjust a number? I forgot the
    > name of the type of dialog in English, but I mean the one with a small up
    > and down "arrow" at the right hand side. Up increases the number, down
    > decreases it. The number can (always?) be entered manually too.
    >
    > Apart form that, a user can select a number formatting of - let's day -
    > 5 digits (xxxxX.XX) before the decimal separator instead of 3 (xxX.xx).
    > Is there a standard way to use a "dynamic" format, e.g. printf("%5d");
    > instead of the default printf("%3d");? I guess there's no special trick
    > for that, but OTOH I've seen apps which follow printf() closely using
    > a kind of external template.
    >
    > Finally, is there a way to specify the precision of a float? I'm getting
    > different results with REXX and C, and assume REXX is the winner. Can I
    > set the "NUMERIC DIGITS" or something like that somehow, or should I
    > avoid the difference by improving my data processing (which is possible
    > in this case, just the average I'm using has to be a float instead of each
    > value to be averaged).
    >
    >
    >
    > ---



    --
    Will Honea

  4. Re: Dynamic formatting

    ML wrote:

    >Is there a standard PM dialog available to adjust a number? I forgot the
    >name of the type of dialog in English, but I mean the one with a small up
    >and down "arrow" at the right hand side. Up increases the number, down
    >decreases it. The number can (always?) be entered manually too.
    >


    It's called "spinbutton" and is a standard control (class WC_SPINBUTTON).
    The update is done automatically, if you set SPBS_NUMERICONLY, but - this
    only works with signed 32-bit integers (-2,147,483,648 - +2,147,483,647).

    >Apart form that, a user can select a number formatting of - let's day -
    >5 digits (xxxxX.XX) before the decimal separator instead of 3 (xxX.xx).
    >Is there a standard way to use a "dynamic" format, e.g. printf("%5d");
    >instead of the default printf("%3d");? I guess there's no special trick
    >for that, but OTOH I've seen apps which follow printf() closely using
    >a kind of external template.
    >
    >Finally, is there a way to specify the precision of a float? I'm getting
    >different results with REXX and C, and assume REXX is the winner. Can I
    >set the "NUMERIC DIGITS" or something like that somehow, or should I
    >avoid the difference by improving my data processing (which is possible
    >in this case, just the average I'm using has to be a float instead of each
    >value to be averaged).
    >


    To get any floating point values in a spinbutton-control, you have to use
    SPBS_ALLCHARACTERS and set an array with at least three entries. Your app
    must change and reset this array, if a SPBN_UPARROW, SPBN_DOWNARROW, SPBN
    _ENDSPIN (notification one of the arrows was used) _or_ SPBN_CHANGE (user
    changed something in the entry field) are received via WM_CONTROL. In the
    latter case, your app must evaluate the user input, then set the array to
    the new value.

    Have a look at the developer section in the Hobes archive - I think there
    are some spinbutton examples where the array technique is used.

    Here's an advanced spinbutton control from my ST-Open programming system,
    but it requires the use of the built-in database engine (there's a skele-
    ton for a program in the V500 folder which does the entire initialisation
    and stuff). One of the choices are pseudo FP values from 32-bit integers:




    Greetings from Augsburg

    Bernhard Schornak


  5. Re: Dynamic formatting

    Jan van Wijk wrote:

    > Yes, but there are only two choices:
    >
    > 1) Use a 'float' like you do, that will give about 6 digits precision
    > 2) Use a 'double' to get, well double of that, about 12 digits :-)
    >

    It's 15 actually. That's because the mantissa of a float uses 24 bits,
    whereas for a double it's 53 - more than twice the amount.


    Michal

  6. Re: Dynamic formatting

    On Sun, 11 Dec 2005 20:54:09 GMT, Michal Necasek wrote:
    > Jan van Wijk wrote:
    >
    >> Yes, but there are only two choices:
    >>
    >> 1) Use a 'float' like you do, that will give about 6 digits precision
    >> 2) Use a 'double' to get, well double of that, about 12 digits :-)
    >>

    > It's 15 actually. That's because the mantissa of a float uses 24 bits,
    > whereas for a double it's 53 - more than twice the amount.


    Well, it's a lot more complicated than that. Normally on an x86
    processor, the floating point operations are done at long double
    precision, and then converted to double or float. VAC++ lets you control
    whether that conversion is done for every element of an expression or
    not (not usually means faster code, but the results may differ from
    representations that stick to double).

    Double uses 52 bits (not 53) for 1 in 2^52 = 2.22e-16 resolution of the
    lsb. Long double uses 64 bits for 1 in 2^64 = 5.42e-20 resolution of the
    lsb.

    A bientot
    Paul
    --
    Paul Floyd http://paulf.free.fr (for what it's worth)
    Surgery: ennobled Gerald.

  7. Re: Dynamic formatting

    [In a very pedantic mode...]

    [A complimentary Cc of this posting was NOT [per weedlist] sent to
    Paul Floyd ], who wrote in article
    :

    > On Sun, 11 Dec 2005 20:54:09 GMT, Michal Necasek wrote:
    > Double uses 52 bits


    correct

    > (not 53)


    Not correct ;-0. Since the leading bit 1 should be added, it is 52
    "signifant" bits, but 53 total bits.

    > for 1 in 2^52 = 2.22e-16 resolution of the lsb.


    Actually, this is also not fully correct. Resolution is between 1 in
    2^52 and 1 in 2^53:

    >perl -wle "$a = 1; $a -= 1.2e-16; printf '%.20g',$a"

    0.99999999999999988898
    >perl -wle "$a = 1; $a += 1.2e-16; printf '%.20g',$a"

    1.000000000000000222

    So for numbers close-to-and-below a power of 2 relative step is about
    1.11e-16 (in other words, the relative error of approximation is about
    5.6e-17), for numbers close-to-and-above a power of 2 relative step is
    about 2.22e-16 (in other words, the relative error of approximation is
    about 1.11e-16). For other numbers the relative error of
    approximation is in between of these values.

    [And if you want to translate this into significant decimal digits,
    yet another beast arises: were is a number w.r.t the closest power
    of 10...]

    > Long double uses 64 bits for 1 in 2^64 = 5.42e-20 resolution of the lsb.


    Of couse, same complications arise here too...

    Hoping this may help some poor soul,
    Ilya

  8. Re: Dynamic formatting

    Paul Floyd wrote:

    > Well, it's a lot more complicated than that. Normally on an x86
    > processor, the floating point operations are done at long double
    > precision, and then converted to double or float.
    >

    That's not quite true. The internal FPU precision is controlled by the
    floating-point control word and can be set to 24, 53 or 64 bits. A
    language runtime will have its own default that the user is free to
    override. It may be accurate to say "using compiler X version Y and its
    runtime will by default perform floating-point calculations with Z bits
    of precision unless user specifies otherwise".

    But I agree that it is "a lot more complicated than that" because on
    the whole computers emulate real number arithmetic extremely poorly and
    numerical computing is a non-trivial scientific field.

    For my purposes, I tend to find that using floating-point arithmetic
    introduces more problems than it solves, but my needs tend to be
    somewhat specific.


    Michal

  9. Re: Dynamic formatting

    On Sun, 11 Dec 2005 06:41:58 UTC, spamgate@hotmai1.com (ML) wrote:

    >
    > Is there a standard PM dialog available to adjust a number? I forgot the
    > name of the type of dialog in English, but I mean the one with a small up
    > and down "arrow" at the right hand side. Up increases the number, down
    > decreases it. The number can (always?) be entered manually too.


    Read the documentation found in the toolkit about spin button.

    > Apart form that, a user can select a number formatting of - let's day -
    > 5 digits (xxxxX.XX) before the decimal separator instead of 3 (xxX.xx).
    > Is there a standard way to use a "dynamic" format, e.g. printf("%5d");
    > instead of the default printf("%3d");? I guess there's no special trick
    > for that, but OTOH I've seen apps which follow printf() closely using
    > a kind of external template.
    >
    > Finally, is there a way to specify the precision of a float? I'm getting
    > different results with REXX and C, and assume REXX is the winner. Can I
    > set the "NUMERIC DIGITS" or something like that somehow, or should I
    > avoid the difference by improving my data processing (which is possible
    > in this case, just the average I'm using has to be a float instead of each
    > value to be averaged).


    There is no PM control that knows something about float. Again study
    the documentation in the toolkit.

    Hint: there are lots of freeware PM programs with either include the
    sources or have theyr sources included in separate packages.
    is a wounderful source for download that to
    study how to program PM.

    If you speaks german you may even try and look there
    in the tips and tricks section. Even as that is far from complete you
    may find some tricks and tips interesting for you.



    --
    Tschau/Bye
    Herbert

    Visit http://www.ecomstation.de the home of german eComStation
    eComStation 1.2 Deutsch ist da!

  10. Re: Dynamic formatting

    spamgate@hotmai1.com (ML) wrote in news:2o8mDlQNA5sb090yn@hotmai1.com:

    >


    >
    >
    >
    > ---


    Dit is een test

  11. Re: Dynamic formatting

    >> I forgot the name of the type of dialog in English, but I mean
    >> the one with a small up and down "arrow" at the right hand side.
    >> Up increases the number, down decreases it. The number can
    >> (always?) be entered manually too.


    > That would be a "spinbox" which is a PM control I think ...
    > AFAIK, there are variants with and without an entryfield.


    Yes, that's the one.

    > Maybe that too, but using a 'double' maybe enough :-)


    Thanks, indeed a double should be enough. If not, I'll change the
    processing in order to work with USHORTs (use pixels instead of
    the guesstimated value each pixel respresents), and just use a
    float or double to display the final result.



    ---

  12. Re: Dynamic formatting


    > Well, it's a lot more complicated than that. Normally on an x86
    > processor, the floating point operations are done at long double
    > precision, and then converted to double or float.


    > VAC++ lets you control whether that conversion is done for every
    > element of an expression or not (not usually means faster code,
    > but the results may differ from representations that stick to
    > double).


    An obvious question: how can I control that with VAC++, if it's
    not too complicated (and relevant)? Not looking at speed, a long
    double always should produce the most accurate result because
    that avoids any possible errors introduced by conversions?



    ---

  13. Re: Dynamic formatting


    > For my purposes, I tend to find that using floating-point
    > arithmetic introduces more problems than it solves, but my
    > needs tend to be somewhat specific.


    I guess that's my second option, use (int)2 cents instead
    of (float)0.02, and ultimately tell the wallet contains an
    ammount of cents/100.



    ---

  14. Re: Dynamic formatting

    On Sun, 11 Dec 2005 23:01:45 +0000 (UTC),
    Ilya Zakharevich wrote:
    > [In a very pedantic mode...]
    >
    > [A complimentary Cc of this posting was NOT [per weedlist] sent to
    > Paul Floyd ], who wrote in article
    >:
    >
    > correct
    >
    >> (not 53)

    >
    > Not correct ;-0. Since the leading bit 1 should be added, it is 52
    > "signifant" bits, but 53 total bits.


    ....

    >> Long double uses 64 bits for 1 in 2^64 = 5.42e-20 resolution of the lsb.

    >
    > Of couse, same complications arise here too...


    You are right of course, I should have remebered that.

    This changes the figures to 1.11e-16 and 2.71e-20.

    A bientot
    Paul
    --
    Paul Floyd http://paulf.free.fr (for what it's worth)
    Surgery: ennobled Gerald.

+ Reply to Thread