Skip to main content
Visitor II
October 2, 2009
Question

The problem with calculations on types float with Cosmic compiler

  • October 2, 2009
  • 4 replies
  • 806 views
Posted on October 02, 2009 at 09:13

The problem with calculations on types float with Cosmic compiler

    This topic has been closed for replies.

    4 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    Hi,

    Why variable wsp_kal not have after the calculations of the correct value 0.000038?

    Example:

    float masa_kal,dzal_kal1,dzal_kal2,dzal_kal,wsp_kal;

    masa_kal = (float)(mas_kal[i+1]-mas_kal[i]); // correct 5

    dzal_kal1 = (float)kal_ram.dz_kal[i+1]; // correct 329602

    dzal_kal2 = (float)kal_ram.dz_kal[i]; // correct 198530

    dzal_kal = (float)(dzal_kal1-dzal_kal2); // correct 131072

    wsp_kal = (float)(masa_kal/dzal_kal); // incorrect 0

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    Hi,

    What is the compiler used in your application and what is the optimization level?

    Please check with the following declaration:

    float masa_kal,dzal_kal1,dzal_kal2,dzal_kal,wsp_kal = 0.0;

    Regards

    mozra

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    Hi,

    I use STVD 4.1.2 and the compiler Cosmic CxSTM8 4.3.1 with optimizations: Minimize code size (+compact). Declaration: float masa_kal,dzal_kal1,dzal_kal2,dzal_kal,wsp_kal=0.0; - not bring the improvement.

    Best regards

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:04

    Hi,

    The setting Display Item from Decimal on Standard in debuger solved the problem.

    Best regards

    krzysztof.skoczek