Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cross Platform float  (Read 2637 times)

0 Members and 1 Guest are viewing this topic.

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Cross Platform float
« on: June 12, 2012, 01:17:46 pm »
In config.hpp SFML defines a bunch of fixed-point data types in a cross-platform way (sf::Int16 etc.). I was wondering why are there no floating point data types (i.e. float or double)? I read somewhere that they are not consistent across all platforms either.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cross Platform float
« Reply #1 on: June 12, 2012, 02:00:07 pm »
The C++ standard doesn't define a specific encoding for floating point numbers, but on all the platforms that SFML supports you can expect floats to use the IEEE-754 representation with fixed sizes.
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Cross Platform float
« Reply #2 on: June 12, 2012, 03:50:29 pm »
Meaing on windows, Mac and Linux float and double will always be the same size?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cross Platform float
« Reply #3 on: June 12, 2012, 04:02:50 pm »
Yes.
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Cross Platform float
« Reply #4 on: June 12, 2012, 06:16:22 pm »
sweet thank you very much!

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: Cross Platform float
« Reply #5 on: June 12, 2012, 06:25:41 pm »
I feel the need to note that long double will vary from compiler to compiler. On Visual Studio it's no different from a double (8 bytes in size), whilst on gcc it's typically 12 bytes (float is 4 and double is 8 ).
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Cross Platform float
« Reply #6 on: June 14, 2012, 11:11:36 am »
Also keep in mind that there might be different precision/rounding if you're using floats for anything that should stay in sync between platforms.