Revision 1.24 by

Revision 1.25 by

… | … | ||
---|---|---|---|

432 | 432 | ||

433 | =over 4 | 433 | =over 4 |

434 | 434 | ||

435 | =item x = ecb_mod (m, n) | 435 | =item x = ecb_mod (m, n) |

436 | 436 | ||

437 | Returns the positive remainder of the modulo operation between C<m> and | 437 | Returns C<m> modulo C<n>, which is the same as the positive remainder |

438 | C<n>, using floored division. Unlike the C modulo operator C<%>, this | 438 | of the division operation between C<m> and C<n>, using floored |

439 | function ensures that the return value is always positive and that the two | 439 | division. Unlike the C remainder operator C<%>, this function ensures that |

440 | the return value is always positive and that the two numbers I<m> and | ||

440 | numbers I<m> and I<m' = m + i * n> result in the same value modulo I<n> - | 441 | I<m' = m + i * n> result in the same value modulo I<n> - in other words, |

441 | the C<%> operator usually has a behaviour change at C<m = 0>. | 442 | C<ecb_mod> implements the mathematical modulo operation, which is missing |

443 | in the language. | ||

442 | 444 | ||

443 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be | 445 | C<n> must be strictly positive (i.e. C<< >= 1 >>), while C<m> must be |

444 | negatable, that is, both C<m> and C<-m> must be representable in its | 446 | negatable, that is, both C<m> and C<-m> must be representable in its |

445 | type. | 447 | type (this typically includes the minimum signed integer value, the same |

448 | limitation as for C</> and C<%> in C). | ||

446 | 449 | ||

447 | Current GCC versions compile this into an efficient branchless sequence on | 450 | Current GCC versions compile this into an efficient branchless sequence on |

448 | many systems. | 451 | many systems. |

449 | 452 | ||

450 | For example, when you want to rotate forward through the members of an | 453 | For example, when you want to rotate forward through the members of an |

– |
Removed lines |

+ |
Added lines |

< |
Changed lines |

> |
Changed lines |