Math
library functions may I use?Math.exp()
and Math.abs()
.
You may also use the constants
Math.POSITIVE_INFINITY
,
Math.NEGATIVE_INFINITY
, and
Math.NaN
.
Double.isNaN(x)
.
Do not write code like (x == Double.NaN)
, as that expression
evaluates to false
for all values of x
, including NaN.
softsign()
function return NaN when x is
positive infinity (or negative infinity) instead of 1 (or –1). Why is this?Double.POSITIVE_INFINITY
or
Double.NEGATIVE_INFINITY
,
tanh()
functions return NaN when x is
larger than 750 (or smaller than –750) instead of 1 (or –1). Why is this?tanh(x)
should return 1.0
;
if \(x \le -20\), then tanh(x)
should return -1.0
.
gcd()
?gcd()
and lcm()
when one (or both) of the arguments are negative?lcm()
return if the least common multiple of the
two arguments is larger than the largest int
value?ArithmeticException
to indicate the arithmetic overflow; we’ll learn about
exceptions later in this course. An alternative would be to change the API to return
the result as a long
(instead of an int
).
amplify()
or mix()
produce samples whose absolute value
is larger than 1, even if all of the input samples are between –1 and +1?int
)
or calling Math.floor(x)
(resulting in a double
).
StdAudio
?Note that the autograder prohibts accessing files unless they are in the same directory as your .java file; do not use operating system specific file paths.double[] samples = StdAudio.read("cow.wav");
changeSpeed()
function changes not only the speed of the sound, but
also the pitch? Is there a way to change the speed without affecting the pitch?