Help in Math Conversion

criss87criss87 Junior MemberPosts: 32
Dear all!

Someone can give me a small help in translate the below math operations in netlinx?

void ConvertToFixed( DOUBLE val, U08 v[4] )
{
U32 fixed;
val = val>15.9?15.9:val;
val = val<-15.9?-15.9:val;
fixed = (U32)(((S32)floor(0.5+8388608.0*val)) & 0x0FFFFFFF);
}


many thanks !!

Criss

Comments

  • a_riot42a_riot42 AMX Wizard Posts: 1,619
    criss87 wrote: »
    void ConvertToFixed( DOUBLE val, U08 v[4] )
    {
    U32 fixed;
    val = val>15.9?15.9:val;
    val = val<-15.9?-15.9:val;
    fixed = (U32)(((S32)floor(0.5+8388608.0*val)) & 0x0FFFFFFF);
    }

    It looks like you may have copied it wrong. v is passed in but never used. But nonetheless, other than the ternary operation which isn't supported in Netlinx, it should just about be the same if you change the types to Netlinx types. I can't guess what the function does with all those magic numbers. Looks like poorly thought out code to me.
    Paul
  • criss87criss87 Junior Member Posts: 32
    At the end I found the solution using first the min and max functions in netlinx and then the floor function that are in the math.axi file, very handy file....


    Sent from my iPad using Tapatalk HD
Sign In or Register to comment.