Learn R Programming

musicMCT (version 0.1.2)

fpunique: Unique real values up to some tolerance

Description

Working with scales in continuous pitch space, many pitches and intervals are irrationals represented as floating point numbers. This can cause arithmetic and rounding errors, leading to it looking like there are more distinct pitches/intervals in the set than there really are. Use fpunique rather than base::unique() whenever you handle scales in continuous pitch space.

Usage

fpunique(x, MARGIN = 0, rounder = 10)

Value

Numeric array of unique elements (vector if MARGIN is 0; matrix otherwise)

Arguments

x

Numeric array whose unique elements are to be determined

MARGIN

Numeric 0, 1, or 2 depending on whether you want unique individual numbers, unique rows, or unique columns, respectively. Defaults to 0.

rounder

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

Details

Sometimes you may need to adjust the tolerance (rounder) to get correct results, especially if you have done several operations in a row which may have introduced rounding errors.

Examples

Run this code
just_dia <- j(dia)
intervals_in_just_dia <- sort(as.vector(sim(just_dia)))
failed_unique_intervals <- unique(intervals_in_just_dia)
fpunique_intervals <- fpunique(intervals_in_just_dia)
length(failed_unique_intervals)
length(fpunique_intervals)

Run the code above in your browser using DataLab