From d0c17de1545a76f52499da30567cde98b4af61f4 Mon Sep 17 00:00:00 2001 From: Koki Fushimi Date: Tue, 3 Mar 2020 18:50:50 +0900 Subject: [PATCH] =?UTF-8?q?Update=20squarewave(x,=20=CE=B8)=20to=20throw?= =?UTF-8?q?=20DomainError.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Waveforms.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Waveforms.jl b/src/Waveforms.jl index ed8e889..e3199f9 100644 --- a/src/Waveforms.jl +++ b/src/Waveforms.jl @@ -21,7 +21,10 @@ squarewave(x::Real) = ifelse(mod2pi(x) < π, 1.0, -1.0) Compute ``2\pi``-periodic square wave of `x` with a duty cycle `θ` and a peak amplitude ``1``. """ -squarewave(x::Real, θ::Real) = ifelse(mod2pi(x) < 2π * θ, 1.0, -1.0) +function squarewave(x::Real, θ::Real) + 0 ≤ θ ≤ 1 || throw(DomainError(θ, "squwarewave(x, θ) is only defined for 0 ≤ θ ≤ 1.")) + ifelse(mod2pi(x) < 2π * θ, 1.0, -1.0) +end @doc raw""" squarewave1(x)