#Why do we need floats instead can't we use doubles?
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Floats are used when memory efficiency is a concern, as they take up half the space of doubles. They are commonly used in graphics programming, where the precision of doubles is not necessary.
Three useful links:
floats take half the place of a double
what do you mean by half the space
float takes 4 bytes, double takes 8 bytes
so thats the only reason for using it..
Computational effort is one measure.
Space can also sometimes translate to speed due to the costs of moving and reading data.
Memory organisation in computers is complex. There are layers to it, and managers that want to keep the memory about to be used as close to the CPU as possible. But the memory closest, is also smaller... if your data is smaller, more of your data can reside closer to the CPU.
It's also more efficient to have memory 'aligned' to a multiple of memory matching the computer's computational model - modern CPUs generally have best performance with data aligned with 32bit and 64bit boundaries, less so with 16bit and 8bit boundaries.
If you think of bytes of memory as a line of boxes on a piece of paper, you can think of this alignment as grouping the boxes into fours or eights.
To achieve the alignment, a 16bit value like a short might be padded with empty space.
So...
It's complicated. Don't worry about it too much at this stage.
You can use
Bigdecimal, number or the exact primitive data
That usecases depends on the context
What kind of problem do you want to solve? @dapper fossil
No i was just learning it and I was just wondering the usage of them and for general use so if I want to make a program it can me help optimised
yeah. their use is generally quite limited. but as others said, occasionally u might find it appropriate. maybe once a decade, depending on what exactly ur coding i guess
ive ran into such a situation maybe 2-3 times in 15 years
where it was actually meaningful
if ur working with certain file structures or embedded hardware etc it can also be more common than with regular software
Yes. So very very rarely a meaningful issue.
i for example remember dealing with a "list" of around 200 million coordinates (lat/lon) (it wasnt an actual list but whatever)
and it was quite heavy on the RAM, storing all that in memory.
the question at the time was whether we should use double or float to represent the lat/lon as that would make a facfor of 2 for the RAM it needs
so we researched the resolution we would have with float lat/lon and it was sth around 10 meters still i think
(which was acceptable for the use case, so we took that)