diff options
author | Karl Williamson <khw@cpan.org> | 2019-03-20 15:31:03 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2019-03-21 11:17:45 -0600 |
commit | 305fe86ebe53ebaec4b94533f37a83774647e346 (patch) | |
tree | 9bd0bf050f8999826ebaae0bebe76a90ff46adb3 /handy.h | |
parent | ef65a74af186beb93566cf827c5f543f4aa14645 (diff) | |
download | perl-305fe86ebe53ebaec4b94533f37a83774647e346.tar.gz |
Generalize macro and move to handy.h
The macro verified that its input was in the range '1' to '9' by using a
subtraction and a single conditional. This commit generalizes this
non-obvious method of avoiding a conditional, and moves it to handy.h so
it can be used in other places.
Diffstat (limited to 'handy.h')
-rw-r--r-- | handy.h | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -1094,6 +1094,12 @@ patched there. The file as of this writing is cpan/Devel-PPPort/parts/inc/misc #define FITS_IN_8_BITS(c) (1) #endif +/* Returns true if c is in the range l..u + * Written with the cast so it only needs one conditional test + */ +#define inRANGE(c, l, u) (__ASSERT_((u) >= (l)) \ + ((WIDEST_UTYPE) (((c) - (l)) | 0) <= ((WIDEST_UTYPE) ((u) - (l))))) + #ifdef EBCDIC # ifndef _ALL_SOURCE /* The native libc isascii() et.al. functions return the wrong results |