L1VM - ranges

I did add two macros to check if variables are in a given range. If not the macro “if” will be executed:

>> ranges.l1h
>> check if variable is out of range
>>
#func int_out_of_range (VAR, MIN, MAX) :(((VAR MIN <) (VAR MAX >) ||) f~ =)
#func double_out_of_range (VAR, MIN, MAX) :(((VAR MIN <d) (VAR MAX >d) ||) f~ =)

So the “int_out_of_range” macro will run this code:

(((VAR MIN <) (VAR MAX >) ||) f~ =)

If the “VAR” value is out of range of “MIN” or “MAX” then it will set the variable “f~” to “1”. Then you can show an error message for example or exit the program.

Here is an example:

// range-new.l1com - Brackets - ranges
//
#include <intr.l1h>
#include <ranges.l1h>
(main func)
	(set int64 1 zero 0)
	(set int64 1 x 23)
	(set int64 1 y 42)
	(set int64 1 r 40)
	(set int64 1 f~ 0)
	(set double 1 xd 23.0)
	(set double 1 yd 42.0)
	(set double 1 rd 40.0)
	(set string s out_of_rangestr "variable r is out of range!")
	(set string s out_of_rangedstr "variable rd is out of range!")
	(set string s in_rangestr "variable r is in range!")
	(set string s in_rangedstr "variable rd is in range!")

	int_out_of_range (r, x, y)
	(f~ if+)
		print_s (out_of_rangestr)
	(else)
		print_s (in_rangestr)
	(endif)
	print_n

	double_out_of_range (rd, xd, yd)
	(f~ if+)
		print_s (out_of_rangedstr)
	(else)
		print_s (in_rangedstr)
	(endif)
	print_n

	exit (zero)
(funcend)