convert double* to float*

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gregosky
    New Member
    • Mar 2011
    • 3

    convert double* to float*

    Hi guys,

    I have written a library that manipulates data stored in double arrays. It took months to fine tune it and here it is, working fine. Everything was great until I started integrating my project with another open source project that uses float arrays. I need to pass my double arrays to the function that requires float arrays.. I am out of ideas how to do that.. I would like to avoid re-writing my project to use float instead of double and I also would like to avoid copying values from double array to float array and pass float array.
    So here is the question - is there any way to pass my double array to function that requires float array?

    Cheers,
    Greg
  • Gregosky
    New Member
    • Mar 2011
    • 3

    #2
    Ok. It is not possible, I will copy double array to float array and do conversion here.

    Thanks anyway,
    Greg

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      It's not possibe to copy a double to a float without potentially losing data. This will produce a compiler warning.

      Your solution here is to rewrte your library to use double instead of float. That's because a float can always be copied to a double.

      float is an obsolete type. A remnant from the days of computers with very tiny memories. Today, unless you can write down on paper a technical reason why you need a float, then use a double.

      Comment

      • Gregosky
        New Member
        • Mar 2011
        • 3

        #4
        I meant that I will copy double array to float array element by element accepting loss of precision :-) That solution works fine.
        Thx anyway.
        This topic can be closed now.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Accepting a loss of precision draws a compiler warning. Mainstream software sets warnings to errors before release. Therefore, in the real world your code would not compile.

          Try to code in such a way as to not have warnings.

          Comment

          Working...