Program ends unexpectedly when I change the vector type from float to double



  • Having issue with a code I am writing for a class and got it to work with floating point numbers, but whenever I change all the variables to being doubles instead of floats (so I can get better precision) it ends unexpectedly after ~25 iterations. The floating point version of the program solved it in 28 iterations. The calculations seem to be printing out completely different results from the beginning. Anyone have any idea of whats going on with it?



  • Can give more information? show your code, show concrete error text?



  • This is the last bit it outputs (note that it interrupts the cout the last line should read .62439 hc inside) I would provide code but its very lengthy and there is not one portion that I can think of to describe the error. Would it be helpful to see how I initialized the vectors?

    21
    -36.225 Temp 1
    2.83614 hr for outside
    30.8 hc for outside
    0.624329 hThe program has unexpectedly finished.

    exited with code -1073741819



  • I supose we need to see the code to tell, what is going wrong. showing only number says nothing.



  • @Gerolf: yep :)

    I think maybe a problem of number alignement or some trouble connected to 32 / 64 bit. Maybe ?



  • As others have said you will have to provide the code.

    Keep in mind that floating point arithmetic is never exact. There will always be round-off errors and the result usually depends on the order of the instructions, the precision and length of datatypes, the compiler and the processor. If you change just one of them results may vary.

    For the same reason you cannot compare floating point numbers to exact values. A frequent error in floating point arithmetic is comparison against 0 and thus missing loop exit conditions. You should always use "qFuzzyCompare":http://doc.qt.nokia.com/4.7-snapshot/qtglobal.html#qFuzzyCompare-2 to compare floating point numbers.

    In addition, using double precision is usually as fast as using float precision and should thus always be preferred.





  • As I know, a forum is a place where other developers - volunteers - try to help others.

    This means that - as I think about - when I need help I try to simplify as possible my question, giving on the post as many information, an example that explain the problem (writing the code) and - when possible - and example that exclude all the code showing the issue as possible out-of-context of my application. Then I can also add lnks "for further details and informations" where the users can find the entire project, the code or whathever else.

    Without offending anyone, the approach of thie request seems a case opened to a - paid - technical support, not a thread that will be helpful for the communityt and help someone to solve his problems.



  • In addition, posting code on "pastebin.com":http://pastebin.com/ (or alike) provides syntax highlighting, indention support due to fixed width font and annotations. Reading code in Google docs is a PITA.



  • Alright, thanks for the help. I agree that writing the code out of context would have been the best route, but there really was no one place that I could single out to help demonstrate my issue without providing all of the code (which is why I didn't provide it originally). I did figure out how to get it to run for some reason the size() function in a for loop created issues but when I changed it to end at a value it ran. Sorry if I have offended anyone for the way I asked for help, just had no idea what could be causing the error.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.