Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are fractional data types generally not implemented? [closed]

Tags:

c++

c

types

I have been working with C/C++ for quite a few years. I have also worked with few other programming languages but none have built-in fractional datatypes. Here I am not talking about the regular decimal datatypes like float. I am referring to regular mathematical fractions having the following form:

Nr/Dr where Dr≠0

What are the challenges that are faced by the developers in implementing such datatypes?


1 Answers

Builtin data types tend to be those that are widely useful, and map more or less efficiently to the underlying architecture. This is no hard and fast rule, but it’s a pretty good rule of thumb.

Fractional data types are neither: they would be widely useful, but limited-precision floating-point types are good enough for 99.9% (or 999/1000, if you prefer) of applications, can be implemented much more efficiently due to hardware support, and have far fewer theoretical and practical limitations because they represent a more general domain of numbers (i.e. not just operations on rational numbers).

There are specific applications where floating point data types don’t cut it, and where arbitrary-precision rational numbers are needed. For those cases, special libraries exist. Cluttering standard libraries with these types would be a waste of effort.

So, essentially, the answer is the same as for any other specialised data type that isn’t widely implemented as a built-in type.

like image 117
Konrad Rudolph Avatar answered Sep 14 '25 14:09

Konrad Rudolph