Why would you use float over double, or double over long double?

后端 未结 5 1203
我寻月下人不归
我寻月下人不归 2021-01-01 13:35

I\'m still a beginner at programming and I always have more questions than our book or internet searches can answer (unless I missed something). So I apologize in advance if

5条回答
  •  不思量自难忘°
    2021-01-01 14:04

    A float uses less memory than a double, so if you don't need your number to be the size of a double, you might as well use a float since it will take up less memory.

    Just like you wouldn't use a bus to drive yourself and a friend to the beach... you would be far better off going in a 2 seater car.

    The same applies for a double over a long double... only reserve as much memory as you are going to need. Otherwise with more complex code you run the risk of using too much memory and having processes slow down or crash.

提交回复
热议问题