#968 printf_fast_f SIGN and leading spaces problem


Hello all!
I'm using SDCC V2.5 MCS-51 on win98 platform.
printf_fast_f with floating point functions with 2 exceptions:

1 - printf_fast_f SIGN is incorrect on values
between 0 - ( -1) .

2 - format "%2.2f" not leads numbers less then 10 with

I tried Small and Large model and it was same problem.

I solved this problem by applying float value to int and
checking the sign.

printf_fast_f ( "%2.2f" , (float) f_val );

batch file for build:
redir -e proj.err SDCC --debug --code-loc 0x0000 --stack-
loc 0xA0 --model-large -DUSE_FLOATS=1 --vc %1.c
rem pause
del %1.hex
ren %1.ihx %1.hex


  • A Hoyle

    A Hoyle - 2008-01-17

    Logged In: YES
    Originator: NO

    I can confirm printf_fast_f has no leading zeros/spaces in floating point.
    Numbers 0 to (-1) not displayed without the (-) sign. Automatic calculation
    of decimal places doesn't work when negative numbers.

    I see know one is assigned to the bug, but is anyone working on it.

    Could some one sent my some docs on how the print_fast_f routine works. I would
    like to help, but it has been 10 years since a wrote any assembler. Please don't assign this bug to me as I don't have the time to commit to fixing it, but I will try.

  • Paul Stoffregen

    Paul Stoffregen - 2008-02-08

    Logged In: YES
    Originator: NO

    I'll look into this (and fix it), eventually....

  • Paul Stoffregen

    Paul Stoffregen - 2008-02-08
    • assigned_to: nobody --> pjs
  • Paul Stoffregen

    Paul Stoffregen - 2008-03-14
    • status: open --> closed
  • Paul Stoffregen

    Paul Stoffregen - 2008-03-14

    Logged In: YES
    Originator: NO


    An integer optimization for zero was being misused by the float printing. Negative sign is always printed properly now.

    The automatic precision scaling wasn't properly handling the sign bit, leading to integer scale round-off for all negative numbers when a format string wasn't specified. Automatic formatting for negative numbers is now handled the same as positive.

    Please note: the first number in the %f format string is the minimum total number of characters to print, not the minimum for only the integer part. So a string "%2.2f" means 2 digits past the decimal point, and because at least 4 characters will always be printed, the minimum total number of 2 is always ignored. Please refer to the gcc printf documentation. A format of "%6.2" is probably what you intended?


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks