summaryrefslogtreecommitdiff
path: root/zap/include
diff options
context:
space:
mode:
Diffstat (limited to 'zap/include')
-rw-r--r--zap/include/zap/bs.h5
-rw-r--r--zap/include/zap/math.h197
-rw-r--r--zap/include/zap/mem.h13
3 files changed, 65 insertions, 150 deletions
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 3a1a1dd..982b355 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -96,8 +96,9 @@
zap_priv_cdecl
-#define zap_ver ((unsigned long)+0x19u)
-#define zap_compatver ((unsigned long)+0x19u) // Programs expecting this version will still compile with the current version.
+#define zap_ver ((unsigned long)+0x1Au) // Programs expecting this version will still compile with the current extension version.
+#define zap_extver ((unsigned long)+0x0u) // The extension versions adds functionality without breaking the existing ones.
+ // The patch version is not public as it only changes implementation details.
#define zap_nopos zap_maxvalsz
diff --git a/zap/include/zap/math.h b/zap/include/zap/math.h
index c6f17c2..2530f4f 100644
--- a/zap/include/zap/math.h
+++ b/zap/include/zap/math.h
@@ -12,108 +12,40 @@
zap_priv_cdecl
typedef struct {
- signed char num;
- signed char den;
-} zap_fracsc;
-typedef struct {
- short num;
- short den;
-} zap_fracs;
-typedef struct {
- int num;
- int den;
-} zap_fraci;
-typedef struct {
- long num;
- long den;
-} zap_fracl;
-typedef struct {
- long long num;
- long long den;
-} zap_fracll;
+ signed char lval;
+ signed char rval;
+} zap_pairsc;
typedef struct {
- signed char quot;
- signed char rem;
-} zap_quotremsc;
-typedef struct {
- short quot;
- short rem;
-} zap_quotrems;
+ short lval;
+ short rval;
+} zap_pairs;
+
typedef struct {
- int quot;
- int rem;
-} zap_quotremi;
+ int lval;
+ int rval;
+} zap_pairi;
+
typedef struct {
- long quot;
- long rem;
-} zap_quotreml;
+ long lval;
+ long rval;
+} zap_pairl;
+
typedef struct {
- long long quot;
- long long rem;
-} zap_quotremll;
-
-zap_priv_nothrw zap_priv_unseq unsigned char zap_abssc(signed char val);
-zap_priv_nothrw zap_priv_unseq unsigned short zap_abss( short val);
-zap_priv_nothrw zap_priv_unseq unsigned int zap_absi( int val);
-zap_priv_nothrw zap_priv_unseq unsigned long zap_absl( long val);
-zap_priv_nothrw zap_priv_unseq unsigned long long zap_absll(long long val);
-zap_priv_nothrw zap_priv_unseq float zap_absf( float val);
-zap_priv_nothrw zap_priv_unseq double zap_absd( double val);
-zap_priv_nothrw zap_priv_unseq long double zap_absld(long double val);
-
-zap_priv_nothrw zap_priv_unseq zap_quotremsc zap_divmodsc(signed char num,signed char den);
-zap_priv_nothrw zap_priv_unseq zap_quotrems zap_divmods( short num,short den);
-zap_priv_nothrw zap_priv_unseq zap_quotremi zap_divmodi( int num,int den);
-zap_priv_nothrw zap_priv_unseq zap_quotreml zap_divmodl( long num,long den);
-zap_priv_nothrw zap_priv_unseq zap_quotremll zap_divmodll(long long num,long long den);
-zap_priv_nothrw zap_priv_unseq zap_quotremsc zap_divmodsc(signed char num,signed char den);
-zap_priv_nothrw zap_priv_unseq zap_quotrems zap_divmods( short num,short den);
-zap_priv_nothrw zap_priv_unseq zap_quotremi zap_divmodi( int num,int den);
-zap_priv_nothrw zap_priv_unseq zap_quotreml zap_divmodl( long num,long den);
-zap_priv_nothrw zap_priv_unseq zap_quotremll zap_divmodll(long long num,long long den);
-
-zap_priv_nothrw zap_priv_unseq unsigned char zap_loguc( unsigned char val,unsigned char n);
-zap_priv_nothrw zap_priv_unseq unsigned short zap_logus( unsigned short val,unsigned short n);
-zap_priv_nothrw zap_priv_unseq unsigned int zap_logui( unsigned int val,unsigned int n);
-zap_priv_nothrw zap_priv_unseq unsigned long zap_logul( unsigned long val,unsigned long n);
-zap_priv_nothrw zap_priv_unseq unsigned long long zap_logull(unsigned long long val,unsigned long long n);
-zap_priv_nothrw zap_priv_unseq char zap_logsc( char val,signed char n);
-zap_priv_nothrw zap_priv_unseq short zap_logs( short val,short n);
-zap_priv_nothrw zap_priv_unseq int zap_logi( int val,int n);
-zap_priv_nothrw zap_priv_unseq long zap_logl( long val,long n);
-zap_priv_nothrw zap_priv_unseq long long zap_logll( long long val,long long n);
-zap_priv_nothrw zap_priv_unseq float zap_logf( float val,float n);
-zap_priv_nothrw zap_priv_unseq double zap_logd( double val,double n);
-zap_priv_nothrw zap_priv_unseq long double zap_logld( long double val,long double n);
-
-zap_priv_nothrw zap_priv_unseq unsigned char zap_expuc( unsigned char val,unsigned char n);
-zap_priv_nothrw zap_priv_unseq unsigned short zap_expus( unsigned short val,unsigned short n);
-zap_priv_nothrw zap_priv_unseq unsigned int zap_expui( unsigned int val,unsigned int n);
-zap_priv_nothrw zap_priv_unseq unsigned long zap_expul( unsigned long val,unsigned long n);
-zap_priv_nothrw zap_priv_unseq unsigned long long zap_expull(unsigned long long val,unsigned long long n);
-zap_priv_nothrw zap_priv_unseq signed char zap_expsc( signed char val,signed char n);
-zap_priv_nothrw zap_priv_unseq short zap_exps( short val,short n);
-zap_priv_nothrw zap_priv_unseq int zap_expi( int val,int n);
-zap_priv_nothrw zap_priv_unseq long zap_expl( long val,long n);
-zap_priv_nothrw zap_priv_unseq long long zap_expll( long long val,long long n);
-zap_priv_nothrw zap_priv_unseq float zap_expf( float val,float n);
-zap_priv_nothrw zap_priv_unseq double zap_expd( double val,double n);
-zap_priv_nothrw zap_priv_unseq long double zap_expld( long double val,long double n);
-
-zap_priv_nothrw zap_priv_unseq unsigned char zap_rootuc( unsigned char val,unsigned char n);
-zap_priv_nothrw zap_priv_unseq unsigned short zap_rootus( unsigned short val,unsigned short n);
-zap_priv_nothrw zap_priv_unseq unsigned int zap_rootui( unsigned int val,unsigned int n);
-zap_priv_nothrw zap_priv_unseq unsigned long zap_rootul( unsigned long val,unsigned long n);
-zap_priv_nothrw zap_priv_unseq unsigned long long zap_rootull(unsigned long long val,unsigned long long n);
-zap_priv_nothrw zap_priv_unseq char zap_rootsc( char val,signed char n);
-zap_priv_nothrw zap_priv_unseq short zap_roots( short val,short n);
-zap_priv_nothrw zap_priv_unseq int zap_rooti( int val,int n);
-zap_priv_nothrw zap_priv_unseq long zap_rootl( long val,long n);
-zap_priv_nothrw zap_priv_unseq long long zap_rootll( long long val,long long n);
-zap_priv_nothrw zap_priv_unseq float zap_rootf( float val,float n);
-zap_priv_nothrw zap_priv_unseq double zap_rootd( double val,double n);
-zap_priv_nothrw zap_priv_unseq long double zap_rootld( long double val,long double n);
+ long long lval;
+ long long rval;
+} zap_pairll;
+
+zap_priv_nothrw zap_priv_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
+zap_priv_nothrw zap_priv_unseq zap_pairs zap_divmods( short num,short den);
+zap_priv_nothrw zap_priv_unseq zap_pairi zap_divmodi( int num,int den);
+zap_priv_nothrw zap_priv_unseq zap_pairl zap_divmodl( long num,long den);
+zap_priv_nothrw zap_priv_unseq zap_pairll zap_divmodll(long long num,long long den);
+zap_priv_nothrw zap_priv_unseq zap_pairsc zap_divmodsc(signed char num,signed char den);
+zap_priv_nothrw zap_priv_unseq zap_pairs zap_divmods( short num,short den);
+zap_priv_nothrw zap_priv_unseq zap_pairi zap_divmodi( int num,int den);
+zap_priv_nothrw zap_priv_unseq zap_pairl zap_divmodl( long num,long den);
+zap_priv_nothrw zap_priv_unseq zap_pairll zap_divmodll(long long num,long long den);
zap_priv_cdeclend
@@ -141,70 +73,47 @@ namespace zap {
namespace zap {
namespace impl {
- template<typename ityp> struct cfractyp {using typ = ityp;};
+ template<typename ityp> struct cpairtyp {using typ = ityp;};
- template<> struct cfractyp<signed char> {using typ = ::zap_fracsc;};
- template<> struct cfractyp<short> {using typ = ::zap_fracs;};
- template<> struct cfractyp<int> {using typ = ::zap_fraci;};
- template<> struct cfractyp<long> {using typ = ::zap_fracl;};
- template<> struct cfractyp<long long> {using typ = ::zap_fracll;};
-
- template<typename ityp> struct cquotremtyp {using typ = ityp;};
-
- template<> struct cquotremtyp<signed char> {using typ = ::zap_quotremsc;};
- template<> struct cquotremtyp<short> {using typ = ::zap_quotrems;};
- template<> struct cquotremtyp<int> {using typ = ::zap_quotremi;};
- template<> struct cquotremtyp<long> {using typ = ::zap_quotreml;};
- template<> struct cquotremtyp<long long> {using typ = ::zap_quotremll;};
+ template<> struct cpairtyp<signed char> {using typ = ::zap_pairsc;};
+ template<> struct cpairtyp<short> {using typ = ::zap_pairs;};
+ template<> struct cpairtyp<int> {using typ = ::zap_pairi;};
+ template<> struct cpairtyp<long> {using typ = ::zap_pairl;};
+ template<> struct cpairtyp<long long> {using typ = ::zap_pairll;};
}
- template<typename typ> class frac {
- public:
- using cfractyp = typename ::zap::impl::cfractyp<typ>::typ;
-
- typ num;
- typ den;
-
- constexpr auto cfrac() noexcept -> cfractyp {
- cfractyp frac;
- frac.num = this->num;
- frac.den = this->den;
- return frac;
- }
- };
-
- template<typename typ> class quotrem {
+ template<typename typ> class pair {
public:
- using cquotremtyp = typename ::zap::impl::cquotremtyp<typ>::typ;
+ using cpairtyp = typename ::zap::impl::cpairtyp<typ>::typ;
- typ quot;
- typ rem;
+ typ lval;
+ typ rval;
- constexpr auto cquotrem() noexcept -> cquotremtyp {
- cquotremtyp quotrem;
- quotrem.quot = this->quot;
- quotrem.rem = this->rem;
- return quotrem;
+ constexpr auto cpair() noexcept -> cpairtyp {
+ cpairtyp pair;
+ pair.lval = this->lval;
+ pair.rval = this->rval;
+ return pair;
}
};
}
namespace zap {
template<typename typ> constexpr auto abs(typ const val) noexcept -> ::zap::usign<typ> {
- using newtyp = ::zap::usign<typ>;
+ using newtyp = ::zap::usign<typ>; // If a floating-point type was used, the new type would be identical.
if (val > typ {0x0}) return static_cast<newtyp>(val);
- return 0x0u-static_cast<newtyp>(val);
+ return typ {0x0} - static_cast<newtyp>(val);
}
- template<typename typ> constexpr auto divmod(typ const num,typ const den) noexcept -> ::zap::quotrem<typ> {
- ::zap::quotrem<typ> quotrem;
+ template<typename typ> constexpr auto divmod(typ const num,typ const den) noexcept -> ::zap::pair<typ> {
+ ::zap::pair<typ> pair;
zap_priv_ulikly (den == 0x0) {
- quotrem.quot = ::zap::inf<typ>;
- quotrem.rem = quotrem.quot;
- return quotrem;
+ pair.lval = ::zap::inf<typ>;
+ pair.rval = pair.lval;
+ return pair;
}
- for (quotrem = ::zap::quotrem<typ> {typ {0x0},num};quotrem.rem >= den;++quotrem.quot,quotrem.rem -= den) {}
- return quotrem;
+ for (pair = ::zap::pair<typ> {typ {0x0},num};pair.rval >= den;++pair.lval,pair.rval -= den);
+ return pair;
}
template<typename typ> constexpr auto exp(typ const val,typ const n) noexcept -> typ {
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h
index 751a601..bd90395 100644
--- a/zap/include/zap/mem.h
+++ b/zap/include/zap/mem.h
@@ -11,10 +11,15 @@
zap_priv_cdecl
-zap_priv_nothrw void * zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num);
-zap_priv_nothrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
-zap_priv_nothrw void zap_fill(void * dest,unsigned char val, zap_sz num);
-zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num);
+typedef struct {
+ void * dest;
+ void * src;
+} zap_cpret;
+
+zap_priv_nothrw zap_cpret zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num);
+zap_priv_nothrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
+zap_priv_nothrw void zap_fill(void * dest,unsigned char val, zap_sz num);
+zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num);
zap_priv_cdeclend