Announcement

Collapse
No announcement yet.

float numbers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • float numbers

    I have some problems with float numbers ...

    problem 1:

    how to declare float constant?

    now I solve the problem by this way:

    var float10[2]; // float variable
    flt_ITOF(float10, 10 ); //Convert integer 10 to float

    I would like to define a float constant with value 10.0
    how to do that ?

    Beside the value 10.0 I need to define a constant with a number like -5.7750E-07 and -4.1830E-12

    Is it possible to have:

    #CONST
    floatA[2]
    floatB[2] ...
    #END



    problem 2:

    how to move float value from one float variable to other float variable?

    simple example:

    var floatA[2]; // float variable A
    var floatB[2]; // float variable B
    flt_ITOF(floatA, 5 ) ; //Convert integer 5 to floatA

    how to move or copy now value from floatA to floatB ?

    now I solve this problem with subtraction of zero from floatA and store result in floatB...

  • #2
    concerning problem 1, I have found in the meantime this:

    https://forum.4dsystems.com.au/node/65427

    but how about the problem 2?

    Comment


    • #3
      Hi

      You could use this command to copy the contents of one array to another

      mem_Copy(floatA, floatB, 4);

      The number 4 is the amont of bytes that you will copy so as it is a float and each array cell is 2 bytes wide, you need to copy 4 over.

      I hope this helps

      Best regards

      Paul

      Comment


      • #4
        The
        https://forum.4dsystems.com.au/node/65427
        solved problem how to define the float constants, but I have calculation problem.
        My constants are too small

        -5.7750E-07 and -4.1830E-12

        If used in calculation, the constants are recognized as zero ( 0.000000000 ) and calculation error is too big. How to increase precision of constants?

        Comment


        • #5
          I have tersted these two constructions:

          example 1:

          #DATA
          byte I_A "3.9083E-03\0"
          byte I_B "-5.7750E-07\0"
          byte I_C "-4.1830E-12\0"

          #END

          var I[3]:= [I_A,I_B,I_C];

          var float_A[2];
          var float_B[2];
          var float_C[2];

          func coco()

          flt_VAL(float_A, I[1]);
          flt_VAL(float_B, I[2]);
          flt_VAL(float_C, I[3]);

          txt_Set(FONT_ID, 4);
          txt_MoveCursor(5, 2);
          flt_PRINT(float_B, "B: %.12f ");

          endfunc


          example 2:

          #DATA
          word I_A "3.9083E-03\0" // I constants
          word I_B "-5.7750E-07\0"
          word I_C "-4.1830E-12\0"

          #END

          var I[3]:= [I_A,I_B,I_C];

          var float_A[4];
          var float_B[4];
          var float_C[4];

          func coco()

          flt_VAL(float_A, I[1]);
          flt_VAL(float_B, I[2]);
          flt_VAL(float_C, I[3]);

          txt_Set(FONT_ID, 4);
          txt_MoveCursor(5, 2);
          flt_PRINT(float_B, "B: %.12f ");

          endfunc


          Unfortunately, both print V: 0.000000000 Can you help?

          Comment


          • #6
            if changed in example (1) above

            flt_VAL(float_A, I[1]);
            flt_VAL(float_B, I[2]);
            flt_VAL(float_C, I[3]);

            txt_Set(FONT_ID, 4);
            txt_MoveCursor(5, 2);
            flt_PRINT(float_B, "B: %.12f ");


            to

            flt_VAL(float_A, I[0]);
            flt_VAL(float_B, I[1]);
            flt_VAL(float_C, I[2]);

            txt_Set(FONT_ID, 4);
            txt_MoveCursor(5, 2);
            flt_PRINT(float_B, "B: %.6e ");


            I am giving correct result at printing. BUT in next calculation the values of float_A , float_B, float_C appears to be still zero...

            Comment


            • #7
              Hi

              You can also do things like this,

              flt_ADD(f, "1.234", "5.678");

              The compiler effectively puts the constants in data, so, of course, you can do it more verbosely like this

              #DATA
              byte flt4 "1.2354\0"
              byte flt5 "1.3e2\0"
              #END

              flt_ADD(f, flt4, flt5);

              Best regards

              Paul

              Comment

              Working...
              X