This is a highly popular and important construct in mathematics. Denoted by two-sided arrow: P <=> Q. As they say, this is a 'biconditional' relation, meaning that if P, then Q, but also vice versa: if Q, then P.

There is also another meaning: if P then Q, but there are no other conditions other than P, that can lead to Q.

'If and only if' is often abbreviated as IFF. Some people unaccustomed to mathematical books may think that IFF is a typo (the author of these lines has also experienced this in past).

I grep'ped some books and source codes with 'if and only if'. Let's see what I've found.

/* * Log a message to stderrif and only if"verbose" is non-zero. * This uses the err(3) functionality. */ void logx(const char *fmt, ...) { va_list ap; if (verbose && fmt != NULL) { va_start(ap, fmt); vwarnx(fmt, ap); va_end(ap); } }

( https://github.com/openbsd/src/blob/master/usr.sbin/rpki-client/main.c )

Here is IFF used to show that a debug message will be printed IFF corresponding debug flags are set. There is no other condition that can lead to this. In other words, if you see a debug message, some debug flag is set. Unless your code or the CPU is buggy, there is no other way to allow this to happen.

/* * Master debug print macros * Print messageif and only if: * 1) Debug print for the current component is enabled * 2) Debug error level or trace level for the print statement is enabled

( https://github.com/torvalds/linux/blob/master/include/acpi/acoutput.h#L265 )

Here is how IFF is used when describing return code.

This usually means, that if a function returns X, there is only *one single* condition that can lead to it.

/* Return 1if and only ifthe PWM interface is safe to use */

( https://github.com/torvalds/linux/blob/master/drivers/hwmon/it87.c#L2978 )

* Returns trueif and only ifthe previous command state was equal to 'old'.

( https://github.com/torvalds/linux/blob/master/drivers/infiniband/ulp/srpt/ib_srpt.c#L797 )

/* * shm_may_destroy - identifies whether shm segment should be destroyed now * * Returns trueif and only ifthere are no active users of the segment and * one of the following is true: * * 1) shmctl(id, IPC_RMID, NULL) was called for this shp * * 2) sysctl kernel.shm_rmid_forced is set to 1. */

( https://github.com/torvalds/linux/blob/master/ipc/shm.c#L342 )

-ENOENT will be returnedif and only ifno GPIO has been assigned to the device/function/index triplet, other error codes are used for cases where a GPIO has been assigned but an error occurred while trying to acquire it.

read-only: legacy interface that indicated whether a memory block was likely to be offlineable or not. Nowadays, the kernel return 1if and only ifit supports memory offlining.

NAME feof — test end-of-file indicator on a stream ... RETURN VALUE The feof() function shall return non-zeroif and only ifthe end-of-file indicator is set for stream.

( POSIX 2017 )

NAME ferror — test error indicator on a stream ... RETURN VALUE The ferror() function shall return non-zeroif and only ifthe error indicator is set for stream.

( POSIX 2017 )

Sometimes, IFF is used to stress the fact that some feature *must/shall* be enabled only IFF corresponding hardware is present.
Or a compiler/OS/API can support this feature.

Standard input and standard output are fully buffered,if and only ifthey do not refer to an interactive device.

( W. Richard Stevens, Stephen A. Rago - Advanced Programming in the UNIX Environment )

10.3.1 Enumeration and Enabling System software enables SMAP by setting the SMAP flag in control register CR4 (bit 21). Processor support for SMAP is enumerated by the CPUID instruction. Specifically, the processor supports SMAP only if CPUID.(EAX=07H,ECX=0H):EBX.SMAP[bit 20] = 1. A processor will allow CR4.SMAP to be set only if SMAP is enumerated by CPUID as described above. CR4.SMAP may be set if paging is disabled (if CR0.PG = 0), but it has no effect on processor operation in that case. In addition, two new instructions: CLAC and STAC (see Section 10.6) are supportedif and only ifSMAP is enumer- ated by CPUID as described above.

( Intel® Architecture Instruction Set Extensions Programming Reference, December 2013 )

ATM_LAYER_STATUS in the control register distinguishes between the two possible physical layers (25 and 155). It is not clear whether the 155 cards can also operate at 25Mbps. We rely on the fact that a card operates at 155if and only ifit has the newer Horizon Ultra ASIC.

( https://github.com/torvalds/linux/blob/master/drivers/atm/horizon.c#L108 )

* Skip the write to HWif and only ifthe device is currently * suspended.

( https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c#L302 )

/* make sure fw funcs are setif and only ifwe have fw*/

( https://github.com/torvalds/linux/blob/master/drivers/gpu/drm/i915/intel_uncore.c#L2176 )

/* Check whether PTP is implemented on this NIC. The DISABLE * operation will succeedif and only ifit is implemented. */

( https://github.com/torvalds/linux/blob/master/drivers/net/ethernet/sfc/ptp.c#L2188 )

CM_POLL_EXTERNAL_POWER_ONLY: poll this batteryif and only ifan external power source is attached. CM_POLL_CHARGING_ONLY: poll this batteryif and only ifthe battery is being charged.

Provide a detect functionif and only ifa chip can be detected reliably.

RFCs are abdundant with the IFF idiom:

The T-bit should be setif and only ifthe router is capable of calculating separate routes for each IP TOS. The E-bit should be set if and only if the attached network belongs to a non-stub area. The rest of the Options field should be set to zero.

( https://www.rfc-editor.org/in-notes/rfc1247.txt )

(1) Change to the up stateif and only ifthe interface is able to send and receive packets. ... (2) Change to the lowerLayerDown stateif and only ifthe interface is prevented from entering the up state because of the state of one or more of the interfaces beneath it in the interface stack. ... (3) Change to the dormant stateif and only ifthe interface is found to be operable, but the interface is waiting for other, external, events to occur before it can transmit or receive packets.

( https://www.rfc-editor.org/in-notes/rfc2233.txt )

NAME complex.h - complex arithmetic ... The macros imaginary and _Imaginary_I shall be definedif and only ifthe implementation supports imaginary types.

( POSIX 2017 )

IFF is often used to stress the fact that a comparison function will return 'true' only if two objects are equal bit-by-bit.

/** * bcmp - returns 0if and only ifthe buffers have identical contents. ... */ int bcmp(const void *a, const void *b, size_t len) { return memcmp(a, b, len); }

( https://github.com/torvalds/linux/blob/master/lib/string.c#L789 )

Two symbols are identicalif and only ifthey have the same name (by string=?). ... Two bytevectors are equal by bytevector=?if and only ifthey have the same length and same contents."

( R. Kent Dybvig - The Scheme Programming Language )

Sets are equalif and only iftheir contents are equal

( Wes McKinney - Python for Data Analysis. Data Wrangling with Pandas, NumPy, and IPython )

Ouch, that pain of floating-point number comparison:

This is not a bug in gawk or in the MPFR library. It is easy to forget that the finite number of bits used to store the value is often just an approximation after proper rounding. The test for equality succeedsif and only ifall bits in the two operands are exactly the same. Because this is not necessarily true after floating-point computations with a particular precision and effective rounding mode, a straight test for equality may not work. Instead, compare the two numbers to see if they are within the desirable delta of each other.

( GNU Awk )

In a binary floating-point format, different computations that produce the same (mathematical) result may differ in their least significant bits. For example, 1.31e0 + 1.69e0 should produce 3.00e0. Likewise, 1.50e0 + 1.50e0 should produce 3.00e0. However, if you were to compare (1.31e0 + 1.69e0) against (1.50e0 + 1.50e0), you might find out that these sums are not equal to one another. The test for equality succeedsif and only ifall bits (or digits) in the two operands are exactly the same. Because this is not necessarily true after two different floating-point computations that should produce the same result, a straight test for equality may not work. ... This means that two strings are equalif and only iftheir lengths are the same and the corresponding characters in the two strings are exactly the same. ... The zero flag is setif and only ifAX = BX. This is the only time AX − BX produces a zero result. Hence, you can use the zero flag to test for equality or inequality.

( Randall Hyde - THE ART OF ASSEMBLY LANGUAGE )

Equality is easy; the ZF flag is setif and only ifoperand1 has the same value as operand2 no matter whether the numbers are interpreted as signed or unsigned.

( Richard C. Detmer -- Introduction to 80x86 Assembly Language and Computer Architecture )

The object type may be a blob, representing the contents of a file, or another tree, representing the contents of a subdirectory. Since trees and blobs, like all other objects, are named by the SHA-1 hash of their contents, two trees have the same SHA-1 nameif and only iftheir contents (including, recursively, the contents of all subdirectories) are identical. This allows Git to quickly determine the differences between two related tree objects, since it can ignore any entries with identical object names.

( https://github.com/git/git/blob/master/Documentation/user-manual.txt#L3013 )

Values of complex types are equalif and only ifboth their real parts are equal and also their imaginary parts are equal. Any two values of arithmetic types from different type domains are equalif and only ifthe results of their conversions to the (complex) result type determined by the usual arithmetic conversions are equal.

( Programming languages — C, N1570, ISO/IEC 9899:201x (AKA C11) )

Here are the rules for an equals( ) method: ... It is symmetric: x.equals(y) must be trueif and only ify.equals(x) is also true.

( Ian Darwin - Java Cookbook )

An implementation of the OpenMP API is compliantif and only ifit compiles and executes all conforming programs according to the syntax and semantics laid out in Chapters 1, 2, 3 and 4. Appendices A, B, C, D, E and F and sections designated as Notes (see Section 1.7 on page 18) are for information purposes only and are not part of the specification.

( OpenMP Application Program Interface )

-- A system can be said to implement this groupif and only if-- all objects in this group are implemented.

( https://www.rfc-editor.org/in-notes/rfc1559.html )

When we create a new ListNode, we can specify the nodes before and after so that the appropriate links can be established. We want it to always be true that b == a.linkif and only ifa = b.prev for any two nodes a and b. To help ensure this invariant, we set self.prev.link = self and self.link.prev = self unless prev or link respectively are None.

( Donald R. Sheehy -- A First Course on Data Structures in Python )

* struct srp_fr_pool - pool of fast registration descriptors * * An entry is available for allocationif and only ifit occurs in @free_list.

( https://github.com/torvalds/linux/blob/master/drivers/infiniband/ulp/srp/ib_srp.h#L286 )

A tree is balancedif and only iffor every node the heights of its two subtrees differ by at most 1.

( Niklaus Wirth - Algorithms and Data Structures )

Something about git's graphs:

When an update changes a branch (or more in general, a ref) that used to point at commit A to point at another commit B, it is called a fast-forward updateif and only ifB is a descendant of A.

( https://github.com/git/git/blob/master/Documentation/git-push.txt#L509 )

Remember the result of an XOR operation is 1if and only ifthe operands are different (look again at the table above).

( The Holy Book of X86 )

The exclusive OR of 2 bits is 0if and only ifboth bits are equal, else the result is 1 as the truth table in Table 3.3 shows.

( Paul A. Carter -- PC Assembly Language )

We can test whether a number is prime as follows: n is primeif and only ifn is its own smallest divisor.

( Structure and Interpretation of Computer Programs )

A set is represented by a bit string in which bit i is 1if and only ifmember i is in the set.

( Beautiful Code: Leading Programmers Explain How They Think )

Another special type of graph is a bipartite graph. A graph G = (V, E) is bipartite if we can split V into two non-overlapping subsets V1 and V2 such that every edge in G connects an element of V1 with an element of V2 . That is, no edge connects two nodes from the same part of the division. Or, alternatively, a graph is bipartiteif and only ifit is 2-colorable.

( Margaret M. Fleck )

A graph is a treeif and only ifit is minimally connected.

( NARSINGH DEO -- Graph Theory with Applications to Engineering & Computer Science )

Tests of Divisibility To test for 2 : A number is divisible by 2if and only ifthe last digit is even. ... To test for 5 : A number is divisible by 5if and only ifit ends in 0 or 5. Otherwise the last digit's excess over 0 or 5 equals the remainder. To test for 6: Test for divisibility by 2 and 3, the factors of 6. A number is divisible by 6if and only ifit is an even number with a digital root divisible by 3. To test for 8: A number is divisible by 8if and only ifthe number formed by its last three digits is divisible by 8.... To test for 9 : A number is divisible by 9if and only ifit has a digital root of 9. If not, the digital root equals the re- mainder. The serial number of the bill has a digital root of 1, therefore it has a remainder of 1 when divided by 9. ... To test for 10: A number is divisible by 10if and only ifit ends in 0. Otherwise the final digit equals the remainder.

( Martin Gardner -- The Unexpected Hanging )

The result of the ~ operator is the bitwise complement of its (promoted) operand (that is, each bit in the result is setif and only ifthe corresponding bit in the converted operand is not set).

( Programming languages — C, N1570, ISO/IEC 9899:201x (AKA C11) )

An AND list evaluates to TRUEif and only ifall of its constituent conditions evaluate to TRUE. The overall condition then evaluates to TRUEif and only ifat least one of its constituent AND lists evaluates to TRUE.

( https://www.rfc-editor.org/rfc/rfc3060 )

The Haskell way:

Haskell is a language with lazy evaluation. From a programmer’s point of view that means that the value is evaluatedif and only ifit is really needed.

( https://hub.packtpub.com/getting-started-haskell/ )

Mathematical writing:

On the other hand, punctuation should always be strictly logical with respect to parentheses and brackets. Put a period inside parenthesesif and only ifthe sentence ending with that period is entirely within the parentheses. The punctuation within parentheses should be correct, independently of the outside context, and the punctu- ation outside the parentheses should be correct if the parenthesized statement would be removed.

( Donald E. Knuth, Tracy Larrabee, and Paul M. Roberts -- Mathematical Writing )

9.3.4.6 Functions ... --- the optional noexcept is presentif and only ifthe exception specification is non-throwing.

( Working Draft, Standard for Programming Language C++ N4892 )

A load succeedsif and only ifthe access is valid for reading ... loadbytes succeedsif and only ifwe have read permissions on the accessed memory area. ... store preserves block validity, permissions, access validity, and bounds. Moreover, a store succeedsif and only ifthe corresponding access is valid for writing.

( https://compcert.org/doc/html/compcert.common.Memtype.html )

/* ** Enable ok button in a dialog boxif and only ifedit item contains text. Edit item must have id of idEditSave */ VOID APIENTRY cDlgCheckOkEnable( HWND hwnd, INT idEdit, WORD message) { if (message == EN_CHANGE) { EnableWindow(GetDlgItem(hwnd, IDOK), (SendMessage(GetDlgItem(hwnd, idEdit), WM_GETTEXTLENGTH, 0, 0L))); } }

( WinNT-related-src/leaked-src/XPSP1/shell/osshell/accesory/calendar/cdlgopen.c )

Two identifiers have the same scopeif and only iftheir scopes terminate at the same point.

( Programming languages — C, N1570, ISO/IEC 9899:201x (AKA C11) )

NAME chown, fchownat — change owner and group of a file ... Changing the group ID is permitted to a process with an effective user ID equal to the user ID of the file, but without appropriate privileges,if and only ifowner is equal to the file’s user ID or (uid_t)−1 and group is equal either to the calling process’ effective group ID or to one of its supplementary group IDs.

( POSIX 2017 )

This is a very important thing to use in practice, like const-correctness. It should be used as much as possible.