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 format

float format

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 4 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.
  • W Offline
    W Offline
    wong1907
    wrote on last edited by
    #1

    hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)

    N S D 3 Replies Last reply
    0
    • W wong1907

      hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)

      N Offline
      N Offline
      Nitron
      wrote on last edited by
      #2

      wong1907 wrote: _queueout=(0.5/5)*(queueinput-60);_ (0.5/5) evaluates to a double-precision value, thus when multiplied bu your float, the result is a double. I usually use doubles and forget about float (I do numerical analyses that may be significant out to 20 decimal places or so). If you are set on using the smaller float, try: float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout = static_cast < float > ((0.5/5)*(queueinput-60)); return (queueout); } Nitron _________________________________________-- message sent on 100% recycled electrons.

      1 Reply Last reply
      0
      • W wong1907

        hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)

        S Offline
        S Offline
        Stephane Rodriguez
        wrote on last edited by
        #3

        Numbers are double, by default. To avoid this warning, you can either disable it (#pragma warning...), or more carefully tell the compiler you are using floats : 0.5 --> 0.5f, 5 --> 5.0f, ...


        How low can you go ?
        (MS retrof_u_ck)

        1 Reply Last reply
        0
        • W wong1907

          hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Any reason why you are using float instead of double?


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          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