(kill(all),0);
0$

/* numbers */

map('signum,[-2, -2/3, -3.4b-2, -7.8b-32]);
[- 1, - 1, - 1.0b0, - 1.0b0]$

map('signum,[0,0.0, 0.0b0]);
[0,0.0,0.0b0]$

map('signum,[2, 2/3, 3.4b-2, 7.8b-32]);
[1,1,1.0b0,1.0b0]$

map('signum, [minf, %pi, %e, %phi, inf]);
[-1,1,1,1,1]$

signum(x);
signum(x)$

signum(rat(x));
signum(x)$

/* reflection */

signum(a) + signum(-a)$
0$

signum(a - b) + signum(b-a);
0$

signum(rat(a-b)) + signum(rat(b-a));
0$

/* expunge negative or positive factors */

signum(sqrt(6) * x);
signum(x)$

signum(-sqrt(5) * x);
-signum(x)$

signum(x^2 + 1);
1$

/* nounform for complex */

(declare(z, complex),0);
0$

signum(z);
signum(z)$

signum(%i);
signum(%i)$

signum(%i - 6);
signum(%i - 6)$

signum(z^2 + 1);
signum(z^2 + 1)$

(assume(p > 0, n < 0, pz >= 0, nz <= 0),0);
0$

signum(p * x);
signum(x)$

signum(n * x);
-signum(x)$

signum(pz * x);
signum(pz * x)$

signum(nz * x);
signum(nz * x)$

signum(p * n * x);
-signum(x)$

signum(signum(x));
signum(x)$

factor(signum(p * x + p));
signum(x + 1)$

factor(signum(p * x^2 + p));
1$

signum(p * x) - signum(x);
0$

signum(n * x) + signum(x);
0$

signum(%i * sqrt(1 - sqrt(2)));
-1$

limit(signum(x),x,minf);
-1$

limit(signum(x),x,0,'minus);
-1$

limit(signum(x),x,0);
ind$

limit(signum(x),x,0,'plus);
1$

limit(signum(x),x,inf);
1$

limit(x * signum(x),x,0);
0$

limit(signum(x+a),x,minf);
-1$

limit(signum(x+a),x,inf);
1$

(assume(notequal(a,0)),0);
0$

limit(signum(x),x,a);
signum(a)$

limit(signum(a*x),x,minf);
-signum(a)$

limit(signum(a*x),x,inf);
signum(a)$

limit(signum(x),x,1/a);
signum(1/a)$

realpart(signum(x));
signum(x)$

imagpart(signum(x));
0$

rectform(signum(x));
signum(x)$

rectform(signum(x + %i));
x/sqrt(x^2+1)+%i/sqrt(x^2+1)$

rectform(signum(42 + %i*x));
%i*x/sqrt(x^2+1764)+42/sqrt(x^2+1764)$

rectform(signum(x+%i*y));
realpart(signum(%i*y+x))+%i*imagpart(signum(%i*y+x))$

(forget(p > 0, n < 0, pz >= 0, nz <= 0,notequal(a,0)), remove(z,complex), 0);
0$

/* SF bug #2242: "integrating function with signum incorrect" */

integrate(x*signum(x^2-1/4),x,-1,0);
-1/4$

/* SF bug #3123: "integrate(x*signum(x^2 - 4), x, 0, 3) yields spurious result" */

integrate(x*signum(x^2 - 4), x, 0, 3);
1/2$

/* integrate can handle signum if it has constant sign between limits of integration */

integrate(x*signum(x^2-1/4),x, -1, -1/2);
-3/8;

integrate(x*signum(x^2-1/4),x, -1/2, 1/2);
0;

integrate(x*signum(x^2-1/4),x, 1/2, 1);
3/8;

/* ... or it's an odd function from -a to a */

integrate(x*signum(x^2-1/4),x,-1,1);
0;

/* other integrate(signum) examples */

integrate(x*signum(x^3 - 8), x, 0, 3);
'integrate(x*signum(x^3 - 8), x, 0, 3);

integrate(x*signum(x^3 - 8), x, -2, 5);
'integrate(x*signum(x^3 - 8), x, -2, 5);

integrate(x*signum(x^3 - 8), x, 2, 5);
21/2;

/* Tests for new (August, 2020) integrals of signum, unit_step, and mod. */

integrate(signum(x),x);
abs(x)$

integrate(-signum(-x),x);
abs(x)$

integrate(signum(a),a,-107,107);
0$

integrate(signum(a),a,0,107);
107$

integrate(unit_step(x),x);
(x + abs(x))/2$

integrate(unit_step(x),x);
(x + abs(x))/2$

integrate(-unit_step(-x),x);
(abs(x)-x)/2$

integrate(mod(x,b),x);
(mod(x,b)^2-b*mod(x,b)+b*x)/2$

integrate(mod(x,b),x,0,b);
b^2/2$

integrate(mod(x,b),x,0,2*b);
b^2$

integrate(mod(x,b),x,0,42*b);
21*b^2$
