Problem with floating point numbers

This is a discussion on Problem with floating point numbers within the C++ Programming forums, part of the General Programming Boards category; I have the following line of code Code: x=fabsf(x)-f3*0.5*powf(0.5,n); It produces the following warning message Code: warning C4244: '=' : ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    197

    Problem with floating point numbers

    I have the following line of code
    Code:
    x=fabsf(x)-f3*0.5*powf(0.5,n);
    It produces the following warning message
    Code:
    warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
    x, f3, and n are all declared as numbers of the type float.

    Why do I get this error message, and how can I fix my code so I do not get it in the future?

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Perhaps all the code would help.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    0.5 is of type double. The float version is 0.5f, this goes for all literals

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    In general, you should use double unless you have a specific reason to use float for your floating point numbers (float is to double as short is to int). That is why a floating point literal is considered to be a double unless you specifically indicate it should be a float with the f.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with floating point values
    By 69gto96z in forum C++ Programming
    Replies: 6
    Last Post: 07-18-2008, 07:01 AM
  2. String and Floating Point Conversion Help
    By dfghjk in forum C++ Programming
    Replies: 14
    Last Post: 05-04-2008, 12:11 PM
  3. Getting a floating point exception
    By SnertyStan in forum C Programming
    Replies: 13
    Last Post: 03-25-2008, 11:00 AM
  4. floating point unit programming problem
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 12-15-2003, 01:16 PM
  5. floating point numbers display something wrong i think
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-27-2002, 03:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21