Home AMX User Forum NetLinx Studio

Help with Mathematic Operation

Greetings,

I am trying to do the following operations to arrive at a value for a timeline step:

1. Divide one integer by another integer resulting in a float with three decimal places
2. Multiply the float by 1000, resuling in an integer

I have tried several things including the format command, but cannot get it to work.

Any suggestions appreciated.

Thanks.

Comments

  • AMXJeffAMXJeff Posts: 450
    Greetings,

    I am trying to do the following operations to arrive at a value for a timeline step:

    1. Divide one integer by another integer resulting in a float with three decimal places
    2. Multiply the float by 1000, resuling in an integer

    I have tried several things including the format command, but cannot get it to work.

    Any suggestions appreciated.

    Thanks.

    1. copy the integer value into a float variable and then do your divide.

    float = integer

    float = float / x

    2. Do the math then copy the float value into a integer variable using type_Cast.

    integer = type_cast(float * 1000);
  • I'll bet you're using a system with Duet firmware. About 18 months ago I started having problems with a calculation that I had been using for years suddenly start always ending up with a result of 4.

    Rather than fight the float, I just rewrote the routine to use integer math.
  • AMXJeffAMXJeff Posts: 450
    AMXJeff wrote: »
    1. copy the integer value into a float variable and then do your divide.

    float = integer

    float = float / x

    2. Do the math then copy the float value into a integer variable using type_Cast.

    integer = type_cast(float * 1000);

    This has been tested to work with Duet Firmware...Do not know the problem Danny is talking about!
  • This is some code that I inherited a few years ago that was used for volume control on a Polycom Vortex. It was burried in an include file, and one day I noticed that it no longer worked. I believe that it always calculates a 4. It has been many months since I had the problem, so naturally I don't remember much.
    LEVEL_EVENT[vdvTP,nTPBtn[25]]
    {
        STACK_VAR CHAR cTEMP[20]
        STACK_VAR FLOAT fVOL
    
        fVOL=(((TPVOL * 40) / 255) - 20)
        cTEMP=FTOA(fVOL)
        VOL=ATOI(cTEMP)
        SEND_STRING dvVORTEX,"'B00GAINO1',ITOA(VOL),13"
        SEND_STRING dvVORTEX,"'B00GAINO2',ITOA(VOL),13"
       
        IF (nDEBUG) { SEND_STRING 0,"'LEVEL_EVENT1- PANEL: ',ITOA(TPVOL),'VORTEX: ',ITOA(VOL)" }
    
    }
    
  • AMXJeffAMXJeff Posts: 450
    This is some code that I inherited a few years ago that was used for volume control on a Polycom Vortex.

    I am assuming TPVOL is an integer?

    fVOL=(((TPVOL * 40) / 255) - 20)

    If the metadata senses an integer type in the math, it will do integer math... This may have changed at one point for some reason or another. The math works correctly if no variables are used... It will do float math... But as soon as you add a variable where it can get metadata to determine what type of math to do...that is what it will do...

    // Will do float math
    fVOL=(((2 * 40) / 255) - 20)


    // solution
    fTemp = TPVOL
    fVOL=(((fTemp * 40) / 255) - 20)
  • Float Math Trouble

    Now my color space conversions work! Very helpful, thanks a lot!
Sign In or Register to comment.