Jump to content
The simFlight Network Forums
Sign in to follow this  
Steve Johnson

Floating Point 64

Recommended Posts

Hi Peter,  my Lua programming has hit a wall.  I have installed a home made GEN AMP stepper instrument which operates from an offset. I can easily set it up to work from an FSX offset 2888. However I am using an add on for the aircraft which gives a much more accurate reading and simulates much more of the electrical system. I know how to read from the add on programs local variables in Lua and to write to a custom offset. I can read from from the add on program and write it to custom offset using ipc.writeDBL and display it to the screen through FSUIPC.  i.e. 30.0000. The problem I have is that I have used all of the custom offset range right through to 66FF and I only have one offset available. The value range represented by the internal variable I am reading from is only 0 - 30, but it is stored in a floating point 64 type variable which uses 8 bytes or 8 offsets.  My question is, is there a way to extract the value and convert it to one byte with the value been within that range (no need for fractions)?  My plan B was to manually convert by writing

ipc.readDBL(0x2888,myVariable)

If myVariable = 30.0000 Then

         myVariable = 30

ipc.writeUB (0x66D4,myVariable)  

 

but this did not work :(

 

Any help would be greatly appreciated.

Regards Steve

 

 

 

Share this post


Link to post
Share on other sites

Hello Steve

You could use math.floor(x)

Returns the largest integer smaller than or equal to x.

Or a function

function toint(n)
    local s = tostring(n)
    local i, j = s:find('%.')
    if i then
        return tonumber(s:sub(1, i-1))
    else
        return n
    end
end

Thomas

Share this post


Link to post
Share on other sites

Hi. When I used math.floor(30.0000) as a test, it returned 30. As soon I replaced the number with my variable it would only return to a double floating point 64 type.  Your function worked perfectly. 

Thank you very much for you help.

 

Regards Steve

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.