Multiplying Math Libraries

Tim asked:

Why do compiler toolchains have their own mathematics libraries? Is it possible to use one library for all controllers, for example https://de.wikipedia.org/wiki/Math.h ?

There are lots of reasons but I think licensing is the big one.

Say you write a math library. It is a pretty big effort as you test it, make it work for your microcontroller, and optimize it so it is fast and small. Is it ok if a paid-for compiler just uses it? If you GPL it, then they have to open-source their code (how will they make money?). Even if you go for the very permissive MIT or Apache licenses, essentially saying  "sure, you can get paid for my work without compensating me in any way”, the compiler vendor has to believe you tested it adequately or they become liable for your bugs.

Thus, it is easier for a compiler vendor to re-write a math library, under their process, using their coding style, and tested by their QA team. Then they know what they have.

Long ago (mid-90s), I wrote some tests for embedded compilers, to see which ones conformed to C and C++ standards. They all failed in different ways: everyone really was writing their own compiler.

Now, you have historical reasons: why would I use your new math implementation when my team wrote a perfectly (!?) good one ten years ago? We invested in that one (and we'll sue you if you try to copy it).

Having a good math library was a huge selling point for compilers. Attaining standards compliance and efficiency for various processors was worth paying for. Now? I don’t know if anyone is still writing paid-for C and C++ compilers such that they’d need a brand new math library.

In essence, I don't think there is only one reason except that a) people needed to make money in order to fund compiler development and b) existing code will always exist.