fpmod: Modulo division with rounding

View source: R/fpunique.R

fpmodR Documentation

Modulo division with rounding

Description

When working with sets in continuous pitch-class spaces (i.e., where octave equivalence is needed), R's normal operator for modulo division %% does not always give ideal results. Values that are very close to (but below) the octave appear to be far from 0. This function uses rounding to give octave-equivalent results that music theorists expect.

Usage

fpmod(set, edo = 12, rounder = 10)

Arguments

set

Numeric vector of pitch-classes in the set

edo

Number of unit steps in an octave. Defaults to 12.

rounder

Numeric (expected integer), defaults to 10: number of decimal places to round to when testing for equality.

Value

Numeric vector the same length as set

Examples

really_small <- 1e-13
c_major <- c(0, 4, 7, 12-really_small)
c_major %% 12
fpmod(c_major, 12)


musicMCT documentation built on June 21, 2026, 9:06 a.m.