TeXipedia

intcalc

Provides robust and expandable arithmetic operations for integer calculations within TeX documents.

Overview

Enables precise integer-based mathematical computations directly within TeX macros and document commands, offering enhanced calculation capabilities compared to basic TeX arithmetic. The package leverages e-TeX's \numexpr extension when available for improved performance and reliability.

  • Supports basic arithmetic operations (addition, subtraction, multiplication, division) with integers
  • Ensures expandable results suitable for use in other TeX commands and definitions
  • Particularly useful for package developers and advanced users needing programmatic calculations
  • Handles edge cases and provides consistent behavior across different TeX engines

Getting Started

To use intcalc, include it in your document preamble:

\documentclass{article}
\usepackage{intcalc}

This package provides expandable arithmetic operations with integers and will automatically use the e-TeX extension \numexpr if available.

Examples

Basic integer calculations using intcalc package.

The result of $3 \times 4 + 2$ is \intcalcAdd{\intcalcMul{3}{4}}{2}.

The result of $(10 - 3) \div 2$ is \intcalcDiv{\intcalcSub{10}{3}}{2}.

The modulo of $17 \bmod 5$ is \intcalcMod{17}{5}.

The sign of $-42$ is \intcalcSgn{-42} and the sign of $42$ is \intcalcSgn{42}.

The absolute value of $-7$ is \intcalcAbs{-7}.

The maximum of $8$ and $12$ is \intcalcMax{8}{12}.

The minimum of $8$ and $12$ is \intcalcMin{8}{12}.