Skip to content

Commit a74222a

Browse files
committed
FEAT: added support for zero? on bitsets.
`zero?` return TRUE if no bits are set in a bitset! ``` >> zero? make bitset! #{0000} == true >> zero? make bitset! #{1000} == false ``` related to: Oldes/Rebol-issues#1353
1 parent fa8fc68 commit a74222a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/core/n-math.c

+4
Original file line numberDiff line numberDiff line change
@@ -803,5 +803,9 @@ enum {SINE, COSINE, TANGENT};
803803
VAL_SET(val, type);
804804
if (Compare_Values(D_ARG(1), D_ARG(2), 1)) return R_TRUE;
805805
}
806+
else if (type == REB_BITSET && Is_Zero_Bitset(VAL_SERIES(D_ARG(1)))) {
807+
return R_TRUE;
808+
}
809+
806810
return R_FALSE;
807811
}

src/core/t-bitset.c

+16
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,22 @@
493493
return PE_BAD_SET;
494494
}
495495

496+
/***********************************************************************
497+
**
498+
*/ REBOOL Is_Zero_Bitset(REBSER *bset)
499+
/*
500+
** Check if all bits are unset.
501+
**
502+
***********************************************************************/
503+
{
504+
REBCNT i;
505+
REBYTE *bp = BIN_HEAD(bset);
506+
507+
for(i = 0; i < SERIES_TAIL(bset); i++) {
508+
if(bp[i] != 0) return FALSE;
509+
}
510+
return TRUE;
511+
}
496512

497513
/***********************************************************************
498514
**

0 commit comments

Comments
 (0)