Global vars as floats?

Discussion in 'General Modification' started by Shiningted, Jul 11, 2021.

Remove all ads!
  1. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,589
    Likes Received:
    317
    The question is implied. I seem to remember running into this once before and I can't remember if, or how, I got around it - mine will only act like integers. Any ideas?
     
  2. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,597
    Likes Received:
    517
    You can convert the float to its underlying 32 bit representation and vice versa. In python this is done via the struct module (struct.pack and unpack).
     
  3. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,597
    Likes Received:
    517
    Oh, and of course you can always use it like a fixed point number, e.g. multiply by 1000 and round it for storing, then the other way around for retrieving.
     
  4. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,589
    Likes Received:
    317
    Gah! Too much effort!
    Yeah I'm doing that, thanks. I have a vague memory that I came up with some cunning fix last time I realised vars were integers (many moons ago), but I probably hallucinated it.
     
  5. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,589
    Likes Received:
    317
    Follow up question: @Sitra Achara , I ran some simulations where I was generating random numbers between 0 and 36 (no prizes for guessing why) - hundreds of thousands of times - and I get zero coming up on average twice as often as I should: even as everything else sort of 'evens out' due to the large sample size. Is there anything about the Mersene that might bias outcomes that way, do you know?
     
  6. Sitra Achara

    Sitra Achara Senior Member

    Joined:
    Sep 1, 2003
    Messages:
    3,597
    Likes Received:
    517
    Not as far as I know. How exactly were you generating the numbers?
     
  7. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,589
    Likes Received:
    317
    Never nmind, I was massively underestimating how many throws I was actually doing (not a relevant number for final outcome). When I added a counter for this, it turns out zero came up every 36.98 times - pretty spot on.
     
Our Host!