hmt-0.15: Haskell Music Theory

Safe HaskellSafe-Inferred
LanguageHaskell98

Music.Theory.Math

Description

Math functions.

Synopsis

Documentation

type R = Double Source

Real (alias for Double).

integer_and_fractional_parts :: RealFrac t => t -> (Integer, t) Source

Type specialised.

fractional_part :: RealFrac a => a -> a Source

http://reference.wolfram.com/mathematica/ref/FractionalPart.html

import Sound.SC3.Plot {- hsc3-plot -}
plotTable1 (map fractional_part [-2.0,-1.99 .. 2.0])

sawtooth_wave :: RealFrac a => a -> a Source

http://reference.wolfram.com/mathematica/ref/SawtoothWave.html

plotTable1 (map sawtooth_wave [-2.0,-1.99 .. 2.0])

rational_pp :: (Show a, Integral a) => Ratio a -> String Source

Pretty printer for Rational that elides denominators of 1.

map rational_pp [1,3/2,2] == ["1","3/2","2"]

ratio_pp :: Rational -> String Source

Pretty print ratio as : separated integers.

map ratio_pp [1,3/2,2] == ["1:1","3:2","2:1"]

rational_simplifies :: Integral a => (a, a) -> Bool Source

Predicate that is true if n/d can be simplified, ie. where gcd of n and d is not 1.

let r = [False,True,False]
in map rational_simplifies [(2,3),(4,6),(5,7)] == r

rational_nd :: Integral t => Ratio t -> (t, t) Source

numerator and denominator of rational.

rational_whole :: Integral a => Ratio a -> Maybe a Source

Rational as a whole number, or Nothing.

rational_whole_err :: Integral a => Ratio a -> a Source

Erroring variant.

realfloat_pp :: RealFloat a => Int -> a -> String Source

Variant of showFFloat. The Show instance for floats resorts to exponential notation very readily.

[show 0.01,realfloat_pp 2 0.01] == ["1.0e-2","0.01"]

float_pp :: Int -> Float -> String Source

Type specialised realfloat_pp.

double_pp :: Int -> Double -> String Source

Type specialised realfloat_pp.

num_diff_str :: (Num a, Ord a, Show a) => a -> String Source

Show only positive and negative values, always with sign.

map num_diff_str [-2,-1,0,1,2] == ["-2","-1","","+1","+2"]
map show [-2,-1,0,1,2] == ["-2","-1","0","1","2"]