fpunique {musicMCT} | R Documentation |
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)
Arguments
x |
Numeric array whose unique elements are to be determined |
MARGIN |
Numeric |
rounder |
Numeric (expected integer), defaults to |
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.
Value
Numeric array of unique elements (vector if MARGIN
is 0;
matrix otherwise)
Examples
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)