Skip to main content
Visitor II
September 10, 2003
Question

float multiplication under Cosmic

  • September 10, 2003
  • 4 replies
  • 878 views
Posted on September 10, 2003 at 07:10

float multiplication under Cosmic

    This topic has been closed for replies.

    4 replies

    Visitor II
    September 8, 2003
    Posted on September 08, 2003 at 17:11

    Hi,

    Im using the C Cosmic Compiler. my application uses a float type variable, and i need to multiply it by another float value:

    float a;

    a = a*1.1;

    when i compiled it, i found out that it took more than 200bytes in the program memory(only the multiplication line!!) - does anyone know what can i do in order to get a smaller application? (i have more that 1 multiplication operator in my app... and only 1.5k of memory)

    Thanks

    Itamar

    Visitor II
    September 9, 2003
    Posted on September 09, 2003 at 23:54

    Itamar,

    For float variables you could use integer maths by ''scaling'' them, i.e. multiply by 10 or 100 or 1000 or some variable constant and then divide by a constant to get final answer.

    For example: (47.01 * 100) * (.05 * 100) = 23,505 then divide by 10000.

    I heard it is suppose to be shorter, but not tried it.

    Good luck,

    DaveF

    Visitor II
    September 9, 2003
    Posted on September 09, 2003 at 23:55

    Itamar,

    For float variables you could use integer maths by ''scaling'' them, i.e. multiply by 10 or 100 or 1000 or some variable constant and then divide by a constant to get final answer.

    For example: (47.01 * 100) * (.05 * 100) = 23,505 then divide by 10000.

    I heard it is suppose to be shorter, but not tried it.

    Good luck,

    DaveF

    Visitor II
    September 10, 2003
    Posted on September 10, 2003 at 07:10

    Hi,

    Usually float are not used on 8bit micros and are reserved for DSPs as the code generated from the library to handle them is way to huge. They are provided mostly as it is part of the ANSI C.

    The most efficient way is to use fractional numbers as you can approximate any real number between 0 and 1 with a good precision using integer fraction with not very big integer (below 20 for example) .

    Ex: 0.555 = 5/9

    By scaling your equations end results you can have very efficient algorithm using only integers.

    The cost will be more thinking in the coding phase.

    Good work.