shithub: riscv

Download patch

ref: f215b660b30cc5e5d318922f545441b4ac14b200
parent: 6409684518f7f3ee35c0ed1933e04e059cb562ab
author: cinap_lenrek <[email protected]>
date: Thu Feb 5 14:55:46 EST 2015

fplot: add modulus % operator

--- a/sys/man/1/fplot
+++ b/sys/man/1/fplot
@@ -29,7 +29,7 @@
 .LR "xmin:xmax ymin:ymax".
 .PP
 Each function to be plotted may be a combination of the independent variable x, 
-the elementary operations (+, -, *, and /), and the functions described in
+the elementary operations (+, -, *, / and %), and the functions described in
 .IR sin (2)
 and
 .IR exp (2).
--- a/sys/src/cmd/fplot.c
+++ b/sys/src/cmd/fplot.c
@@ -49,6 +49,7 @@
 void sub(void) { sp--; *sp -= *(sp+1); }
 void mul(void) { sp--; *sp *= *(sp+1); }
 void div(void) { sp--; *sp /= *(sp+1); }
+void mod(void) { sp--; *sp = fmod(*sp, *(sp+1)); }
 void pot(void) { sp--; *sp = pow(*sp, *(sp+1)); }
 void osin(void) { *sp = sin(*sp); }
 void ocos(void) { *sp = cos(*sp); }
@@ -72,6 +73,7 @@
 	"-",	OBINARY,	0,	0,	sub,
 	"*",	OBINARY,	0,	100,	mul,
 	"/",	OBINARY,	0,	100,	div,
+	"%",	OBINARY,	0,	100,	mod,
 	"^",	OBINARY,	1,	200,	pot,
 	"sin",	OUNARY,		0,	50,	osin,
 	"cos",	OUNARY,		0,	50,	ocos,