Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. float and double data type

float and double data type

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shir_k
    wrote on last edited by
    #1

    Hi, The value stored in Float and same value when stored in double there is difference in the value Why? Eg: void main() { CString str; union { float f1; unsigned long a1; }un1; union { double d_f1; unsigned long d_a1; }d_un1; float flt; double d_flt; un1.a1 = 0; un1.f1 = 0.0; un1.a1=0x6fffffff; flt = un1.f1; d_un1.d_a1 = 0; d_un1.d_f1 = 0.0; d_un1.d_a1=0x6fffffff; d_flt = d_un1.d_f1; } Output: d_flt 9.2837315805324e-315 flt 1.58456e+029 d_un1.d_f1 9.2837315805324e-315 un1.f1 1.58456e+029 I need the variable to hold value upto 0xffffffff as float cannot hold it i used double but there is a variation in the value if value is <7fffffffff.Is due to IEEE internal representation.HOw to resolve this. Thanks

    CPalliniC 1 Reply Last reply
    0
    • S shir_k

      Hi, The value stored in Float and same value when stored in double there is difference in the value Why? Eg: void main() { CString str; union { float f1; unsigned long a1; }un1; union { double d_f1; unsigned long d_a1; }d_un1; float flt; double d_flt; un1.a1 = 0; un1.f1 = 0.0; un1.a1=0x6fffffff; flt = un1.f1; d_un1.d_a1 = 0; d_un1.d_f1 = 0.0; d_un1.d_a1=0x6fffffff; d_flt = d_un1.d_f1; } Output: d_flt 9.2837315805324e-315 flt 1.58456e+029 d_un1.d_f1 9.2837315805324e-315 un1.f1 1.58456e+029 I need the variable to hold value upto 0xffffffff as float cannot hold it i used double but there is a variation in the value if value is <7fffffffff.Is due to IEEE internal representation.HOw to resolve this. Thanks

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      shir_k wrote:

      I need the variable to hold value upto 0xffffffff as float

      Why? I mean: cannot you use the unsigned integer instead?

      shir_k wrote:

      Is due to IEEE internal representation.HOw to resolve this

      The above is true and there's nothing to resolve. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      S 1 Reply Last reply
      0
      • CPalliniC CPallini

        shir_k wrote:

        I need the variable to hold value upto 0xffffffff as float

        Why? I mean: cannot you use the unsigned integer instead?

        shir_k wrote:

        Is due to IEEE internal representation.HOw to resolve this

        The above is true and there's nothing to resolve. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        S Offline
        S Offline
        shir_k
        wrote on last edited by
        #3

        Yes we can use unsigned integer but am more concerned about float value. Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value. Thanks

        CPalliniC 1 Reply Last reply
        0
        • S shir_k

          Yes we can use unsigned integer but am more concerned about float value. Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value. Thanks

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          shir_k wrote:

          Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value.

          You cannot have such a function since the float value of 0xffffffff, according to IEEE 754 standard belongs to the NaN (Not a Number) set. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          In testa che avete, signor di Ceprano?

          S 1 Reply Last reply
          0
          • CPalliniC CPallini

            shir_k wrote:

            Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value.

            You cannot have such a function since the float value of 0xffffffff, according to IEEE 754 standard belongs to the NaN (Not a Number) set. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            S Offline
            S Offline
            shir_k
            wrote on last edited by
            #5

            ok, thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups