this post was submitted on 22 Dec 2023
188 points (96.1% liked)

STOP DOING SCIENCE

413 readers
1 users here now

A community for memes like this.

Not at all affiliated with the subreddit, I just shamelessly stole the name.

Rules:

founded 1 year ago
MODERATORS
 
top 7 comments
sorted by: hot top controversial new old
[–] [email protected] 24 points 1 year ago* (last edited 1 year ago)

This but unironically

[–] [email protected] 19 points 1 year ago
[–] [email protected] 11 points 1 year ago (2 children)

Ok but actually though, can someone explain why we can't use integers to emulate floats. Why is there a dedicated fpu

[–] [email protected] 18 points 1 year ago

It’s been a long while since I last dealt with the float specification (IEE 754), but what I recall is this:

Floating points allow better precision along a wide range of numbers with a smaller data type compared to fixed point data in most cases. Fixed point can often be emulated by integers. Its far from perfect, but for scientific computing it’s often good enough.

If you use integers to emulate floats, there will be less precision in either the integer part, or the decimal part. You have to make a tradeoff. If you know about what types of data you will be collecting, you can get better precision compared to floating point.

Integer arithmetic can be implemented with simple logic gate layouts, and in most processors, addition/subtraction/multiplication takes very few cycles, and is generally done with a single assembly instruction. IIRC, you can, for the most part, use standard add/subtract with fixed point numbers. Floating point operations, on the other hand, are much more complex due to the nature of floating point numbers potentially having the decimal in different places. In order to break that down into standard integer based assembly code, you must do many more steps. In order to make things faster, you can create dedicated processors with more complex logic gate layouts designed around floats (FPUs) for significantly faster floating point operations.

[–] [email protected] 6 points 1 year ago (1 children)

Let's say our integers are 64 bit, say we put half before the point. Now our largest value is just below 4 294 967 296, a 32 bit float goes to 3.4*10^38. The representation also enables some operations to be faster (multiplication, division iirc).

[–] [email protected] 6 points 1 year ago

Floats have a wider range, at the cost of not having full coverage over that range. Even the integers in that range cannot be exactly represented

[–] [email protected] 2 points 1 year ago

I feel like a lot of conditionals involving floats make more sense if you convert it to an integer and do bitwise operations lmao. Like to check if something is a real number just check to see if the exponent is not in the space used by infinities and nans