All C math functions seems to have an understandable name, but I can't find what the fdim acronym stands for. (fdim computes the positive difference of it two floating-point inputs).
I searched the ISO-C working group's document archive, and noticed that most of the proposals for the floating-point enhancements to what would become C99 were contributed by Jim Thomas. Best I can tell, fdim
was included in the draft new standard prior to 1996, and unfortunately the archive does not provide links to electronic copies for proposals from that time.
So I contacted Mr. Thomas directly via email and received a response, the relevant portion of which I quote here with his permission:
From: Jim Thomas
To: Norbert Juffa
Time: Sat 2/15/2020 8:42 AM
Subject: Re: Naming of, and rationale for, the fdim() function in ISO-C99
[...]
The C fdim function is the C versions for the Fortran DIM (positive difference) function. The C function, and its name, were intended for programmers porting code form Fortran to C.
This confirms the linkage with Fortran alluded to in comments. As for the name DIM
itself, Ctx's answer addresses this as well as one could hope for in the case of a minor function that has been around for fifty years.
In comments below the question, Mark Dickinson pointed to the Fortran 66 standard, which on page 23 defined Fortran's DIM
function as a₁ - Min (a₁, a₂). This provides further evidence that the name DIM
is a contraction of DIfference and Minimum.
My guess is, that it is a composition from difference
and max
, because this is what the function does.
Pseudo-code
double fdim(x, y) {
float tmp = x - y; // 1st step: "di"fference
float result = fmax(tmp, 0); // 2nd step: "m"aximum
return result;
}
Same nomenclature for example with fma(a, b, c)
, which means "multiply" and "add" (a*b+c)
Edit:
The function indeed occurred even earlier in Fortran, where the function
DIM(number, number)
is defined as
A function that returns the value of the first argument minus the minimum (MIN) of the two arguments.
so the function name is derived from difference and minimum here. See the F77 DIM manual
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With