Pyoz_
Pyoz_

Reputation: 59

What does the fdim acronym stand for?

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).

Upvotes: 5

Views: 423

Answers (3)

njuffa
njuffa

Reputation: 26085

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.

Upvotes: 5

Ctx
Ctx

Reputation: 18420

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

Upvotes: 4

Lundin
Lundin

Reputation: 213799

I can't find any good published first source for this. fdim first appeared in C99, and the C99 rationale (7.12.12) only mentions this:

The names for fmax, fmin and fdim have f prefixes to allow for extension integer versions following the example of fabs and abs.

But we could already guess as much, the f stands for floating point.

Similarly, the last f in fdimf stands for float, and the last l in fdiml stands for long double. These prefix/postfix letters are commonly used in the standard libs.

Upvotes: 1

Related Questions