libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

libsheepyCSmallDouble.c (30019B)


      1 // MIT License
      2 //
      3 // Copyright (c) 2026 Remy Noulin
      4 //
      5 // Permission is hereby granted, free of charge, to any person obtaining a copy
      6 // of this software and associated documentation files (the "Software"), to deal
      7 // in the Software without restriction, including without limitation the rights
      8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9 // copies of the Software, and to permit persons to whom the Software is
     10 // furnished to do so, subject to the following conditions:
     11 //
     12 // The above copyright notice and this permission notice shall be included in all
     13 // copies or substantial portions of the Software.
     14 //
     15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21 // SOFTWARE.
     22 
     23 #include "../libsheepyObject.h"
     24 #include "libsheepyCSmallDouble.h"
     25 #include "libsheepyCSmallDoubleInternal.h"
     26 
     27 #define internal static
     28 
     29 #include <stdint.h>
     30 #include <stdlib.h>
     31 #include <stdbool.h>
     32 #include <stdio.h>
     33 
     34 void initiateSmallDouble(smallDoublet *self);
     35 void registerMethodsSmallDouble(smallDoubleFunctionst *f);
     36 void initiateAllocateSmallDouble(smallDoublet **self);
     37 void finalizeRecycleSmallDouble(void *arg UNUSED);
     38 void finalizeSmallDouble(void);
     39 smallDoublet* allocSmallDouble(double value);
     40 void cleanUpSmallDoubleTerminateG(smallDoublet **val);
     41 void cleanUpSmallDoubleFreeLocalG(smallDoublet *val);
     42 void cleanUpSmallDoubleFreeG(smallDoublet **val);
     43 void cleanUpSmallDoubleFinishG(smallDoublet **val);
     44 internal void freeSmallDouble(smallDoublet *self);
     45 internal void terminateSmallDouble(smallDoublet **self);
     46 internal char* toStringSmallDouble(smallDoublet *self);
     47 internal smallDoublet* duplicateSmallDouble(smallDoublet *self);
     48 internal void  smashSmallDouble(smallDoublet **self);
     49 #if (NFreeStackCheck)
     50 internal void finishSmallDouble(smallDoublet **self);
     51 #else
     52 internal void finishSmallDouble(smallDoublet **self);
     53 #endif
     54 internal const char* helpSmallDouble(smallDoublet UNUSED *self);
     55 internal double  getSmallDouble(smallDoublet *self);
     56 internal smallDoublet*  setSmallDouble(smallDoublet *self, double value);
     57 internal smallDoublet* setBoolSmallDouble(smallDoublet* self, bool p2);
     58 internal smallDoublet* setInt64SmallDouble(smallDoublet* self, int64_t p2);
     59 internal smallDoublet* setInt32SmallDouble(smallDoublet* self, int32_t p2);
     60 internal smallDoublet* setUint32SmallDouble(smallDoublet* self, uint32_t p2);
     61 internal smallDoublet* setUint64SmallDouble(smallDoublet* self, uint64_t p2);
     62 internal smallDoublet* setSSmallDouble(smallDoublet* self, const char* p2);
     63 internal smallDoublet* setSmallBoolSmallDouble(smallDoublet* self, smallBoolt* p2);
     64 internal smallDoublet* setSmallDoubleSmallDouble(smallDoublet* self, smallDoublet* p2);
     65 internal smallDoublet* setSmallIntSmallDouble(smallDoublet* self, smallIntt* p2);
     66 internal smallDoublet* setSmallJsonSmallDouble(smallDoublet* self, smallJsont* p2);
     67 internal smallDoublet* setSmallStringSmallDouble(smallDoublet* self, smallStringt* p2);
     68 internal double* getPSmallDouble(smallDoublet *self);
     69 internal bool equalSmallDoubleCha(smallDoublet* self, char p2);
     70 internal bool equalSmallDoubleChar(smallDoublet* self, const char * p2);
     71 internal bool equalSmallDoubleBase(smallDoublet* self, baset* p2);
     72 internal bool equalSmallDoubleBool(smallDoublet* self, bool p2);
     73 internal bool equalSmallDoubleDouble(smallDoublet* self, double p2);
     74 internal bool equalSmallDoubleInt64(smallDoublet* self, int64_t p2);
     75 internal bool equalSmallDoubleInt32(smallDoublet* self, int32_t p2);
     76 internal bool equalSmallDoubleUint32(smallDoublet* self, uint32_t p2);
     77 internal bool equalSmallDoubleUint64(smallDoublet* self, uint64_t p2);
     78 internal bool equalSmallDoubleSmallBool(smallDoublet* self, smallBoolt* p2);
     79 internal bool equalSmallDoubleSmallBytes(smallDoublet* self, smallBytest* p2);
     80 internal bool equalSmallDouble(smallDoublet* self, smallDoublet* p2);
     81 internal bool equalSmallDoubleSmallInt(smallDoublet* self, smallIntt* p2);
     82 internal bool equalSmallDoubleSmallJson(smallDoublet* self, smallJsont* p2);
     83 internal bool equalSmallDoubleSmallString(smallDoublet* self, smallStringt* p2);
     84 internal smallDoublet* readFileSmallDouble(smallDoublet *self, const char *filePath);
     85 internal smallDoublet* readFileSmallJsonSmallDouble(smallDoublet *self, smallJsont *filePath);
     86 internal smallDoublet* readFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath);
     87 internal smallDoublet* readStreamSmallDouble(smallDoublet *self, FILE *fp);
     88 internal int writeFileSmallDouble(smallDoublet *self, const char *filePath);
     89 internal int writeFileSmallJsonSmallDouble(smallDoublet *self, smallJsont *filePath);
     90 internal int writeFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath);
     91 internal int writeStreamSmallDouble(smallDoublet *self, FILE *fp);
     92 internal int appendFileSmallDouble(smallDoublet *self, const char *filePath);
     93 internal int appendFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath);
     94 smallDoublet*      duplicateSmallDoubleG          (smallDoublet *self);
     95 double             getDoubleSmallDoubleG          (smallDoublet *self, double retType UNUSED, int64_t index UNUSED);
     96 smallDoublet* setBoolSmallDoubleG(smallDoublet* self, bool p2);
     97 smallDoublet* setSmallDoubleG(smallDoublet* self, double p2);
     98 smallDoublet* setInt64SmallDoubleG(smallDoublet* self, int64_t p2);
     99 smallDoublet* setInt32SmallDoubleG(smallDoublet* self, int32_t p2);
    100 smallDoublet* setUint32SmallDoubleG(smallDoublet* self, uint32_t p2);
    101 smallDoublet* setUint64SmallDoubleG(smallDoublet* self, uint64_t p2);
    102 smallDoublet* setSSmallDoubleG(smallDoublet* self, const char* p2);
    103 smallDoublet* setSmallBoolSmallDoubleG(smallDoublet* self, smallBoolt* p2);
    104 smallDoublet* setSmallDoubleSmallDoubleG(smallDoublet* self, smallDoublet* p2);
    105 smallDoublet* setSmallIntSmallDoubleG(smallDoublet* self, smallIntt* p2);
    106 smallDoublet* setSmallJsonSmallDoubleG(smallDoublet* self, smallJsont* p2);
    107 smallDoublet* setSmallStringSmallDoubleG(smallDoublet* self, smallStringt* p2);
    108 double*            getDoublePSmallDoubleG         (smallDoublet *self, double* retType UNUSED, int64_t index UNUSED);
    109 bool equalSmallDoubleChaG(smallDoublet* self, char p2);
    110 bool equalSmallDoubleCharG(smallDoublet* self, const char * p2);
    111 bool equalSmallDoubleBaseG(smallDoublet* self, baset* p2);
    112 bool equalSmallDoubleBoolG(smallDoublet* self, bool p2);
    113 bool equalSmallDoubleDoubleG(smallDoublet* self, double p2);
    114 bool equalSmallDoubleInt64G(smallDoublet* self, int64_t p2);
    115 bool equalSmallDoubleInt32G(smallDoublet* self, int32_t p2);
    116 bool equalSmallDoubleUint32G(smallDoublet* self, uint32_t p2);
    117 bool equalSmallDoubleUint64G(smallDoublet* self, uint64_t p2);
    118 bool equalSmallDoubleSmallBoolG(smallDoublet* self, smallBoolt* p2);
    119 bool equalSmallDoubleSmallBytesG(smallDoublet* self, smallBytest* p2);
    120 bool equalSmallDoubleFG(smallDoublet* self, smallDoublet* p2);
    121 bool equalSmallDoubleSmallIntG(smallDoublet* self, smallIntt* p2);
    122 bool equalSmallDoubleSmallJsonG(smallDoublet* self, smallJsont* p2);
    123 bool equalSmallDoubleSmallStringG(smallDoublet* self, smallStringt* p2);
    124 smallDoublet*  readFileSmallDoubleG     (smallDoublet *self, const char *filePath);
    125 smallDoublet* readFileSmallJsonSmallDoubleG  (smallDoublet *self, smallJsont *filePath);
    126 smallDoublet* readFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath);
    127 smallDoublet* readStreamSmallDoubleG         (smallDoublet *self, FILE *fp);
    128 int  writeFileSmallDoubleG    (smallDoublet *self, const char *filePath);
    129 int writeFileSmallJsonSmallDoubleG  (smallDoublet *self, smallJsont *filePath);
    130 int writeFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath);
    131 int writeStreamSmallDoubleG         (smallDoublet *self, FILE *fp);
    132 int appendFileSmallDoubleFG           (smallDoublet *self, const char *filePath);
    133 int appendFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath);
    134 
    135 void initiateSmallDouble(smallDoublet *self) {
    136 
    137   self->type = "smallDouble";
    138   if (!smallDoubleF) {
    139     isError(smallDoubleF, malloc(sizeof(smallDoubleFunctionst))) {
    140       self->f = NULL;
    141       return;
    142     }
    143     registerMethodsSmallDouble(smallDoubleF);
    144   }
    145   self->f     = smallDoubleF;;
    146 
    147   self->value = NULL;
    148 }
    149 
    150 void registerMethodsSmallDouble(smallDoubleFunctionst *f) {
    151 
    152   f->free                  = freeSmallDouble;
    153   f->terminate             = terminateSmallDouble;
    154   f->toString              = toStringSmallDouble;
    155   f->duplicate             = duplicateSmallDouble;
    156   f->smash                 = smashSmallDouble;
    157   f->finish                = finishSmallDouble;
    158   f->help                  = helpSmallDouble;
    159   f->get                   = getSmallDouble;
    160   f->set                   = setSmallDouble;
    161   f->setBool               = setBoolSmallDouble;
    162   f->setInt64              = setInt64SmallDouble;
    163   f->setInt32              = setInt32SmallDouble;
    164   f->setUint32             = setUint32SmallDouble;
    165   f->setUint64             = setUint64SmallDouble;
    166   f->setS                  = setSSmallDouble;
    167   f->setSmallBool          = setSmallBoolSmallDouble;
    168   f->setSmallDouble        = setSmallDoubleSmallDouble;
    169   f->setSmallInt           = setSmallIntSmallDouble;
    170   f->setSmallJson          = setSmallJsonSmallDouble;
    171   f->setSmallString        = setSmallStringSmallDouble;
    172   f->getP                  = getPSmallDouble;
    173   f->equalCha              = equalSmallDoubleCha;
    174   f->equalChar             = equalSmallDoubleChar;
    175   f->equalBase             = equalSmallDoubleBase;
    176   f->equalBool             = equalSmallDoubleBool;
    177   f->equalDouble           = equalSmallDoubleDouble;
    178   f->equalInt64            = equalSmallDoubleInt64;
    179   f->equalInt32            = equalSmallDoubleInt32;
    180   f->equalUint32           = equalSmallDoubleUint32;
    181   f->equalUint64           = equalSmallDoubleUint64;
    182   f->equalSmallBool        = equalSmallDoubleSmallBool;
    183   f->equalSmallBytes       = equalSmallDoubleSmallBytes;
    184   f->equal                 = equalSmallDouble;
    185   f->equalSmallInt         = equalSmallDoubleSmallInt;
    186   f->equalSmallJson        = equalSmallDoubleSmallJson;
    187   f->equalSmallString      = equalSmallDoubleSmallString;
    188   f->readFile              = readFileSmallDouble;
    189   f->readFileSmallJson     = readFileSmallJsonSmallDouble;
    190   f->readFileSmallString   = readFileSmallStringSmallDouble;
    191   f->readStream            = readStreamSmallDouble;
    192   f->writeFile             = writeFileSmallDouble;
    193   f->writeFileSmallJson    = writeFileSmallJsonSmallDouble;
    194   f->writeFileSmallString  = writeFileSmallStringSmallDouble;
    195   f->writeStream           = writeStreamSmallDouble;
    196   f->appendFile            = appendFileSmallDouble;
    197   f->appendFileSmallString = appendFileSmallStringSmallDouble;
    198 }
    199 
    200 void initiateAllocateSmallDouble(smallDoublet **self) {
    201 
    202   if (self) {
    203     #if (recycleContainers)
    204     initAllocateRecycle(smallDoublet);
    205     #else
    206     isError(*self, malloc(sizeof(smallDoublet)))
    207       return;
    208     #endif
    209     if (*self) {
    210       initiateSmallDouble(*self);
    211       if (!(*self)->f) {
    212         finishSmallDouble(self);
    213 }
    214   }
    215     }
    216       }
    217 
    218 void finalizeRecycleSmallDouble(void *arg UNUSED) {
    219 
    220   #if (recycleContainers)
    221   finalizeRecycle
    222   #endif
    223   // recycleContainers
    224 }
    225 
    226 void finalizeSmallDouble(void) {
    227 
    228   if (smallDoubleF) {
    229     free(smallDoubleF);
    230     smallDoubleF = NULL;
    231   }
    232   finalizeRecycleSmallDouble(NULL);
    233 }
    234 
    235 smallDoublet* allocSmallDouble(double value) {
    236   smallDoublet *r = NULL;
    237 
    238   initiateAllocateSmallDouble(&r);
    239   if (!r) {
    240     return(NULL);
    241   }
    242   isError(r->value, allocSDouble(value)) {
    243     terminateO(r);
    244     return(NULL);
    245   }
    246   return(r);
    247 }
    248 
    249 void cleanUpSmallDoubleTerminateG(smallDoublet **val) {
    250 
    251   terminateO(*val);
    252 }
    253 
    254 void cleanUpSmallDoubleFreeLocalG(smallDoublet *val) {
    255 
    256   freeO(val);
    257 }
    258 
    259 void cleanUpSmallDoubleFreeG(smallDoublet **val) {
    260 
    261   freeO(*val);
    262 }
    263 
    264 void cleanUpSmallDoubleFinishG(smallDoublet **val) {
    265 
    266   finishO(*val);
    267 }
    268 
    269 internal void freeSmallDouble(smallDoublet *self) {
    270 
    271   if (self->value) {
    272     free(self->value);
    273     self->value = NULL;
    274   }
    275   return;
    276 }
    277 
    278 internal void terminateSmallDouble(smallDoublet **self) {
    279 
    280   freeSmallDouble(*self);
    281   finishSmallDouble(self);
    282 }
    283 
    284 
    285 internal char* toStringSmallDouble(smallDoublet *self) {
    286   char *s = NULL;
    287 
    288   if (!self->value) {
    289     return(NULL);
    290   }
    291   s = malloc(256*sizeof(char));
    292   if (!s) {
    293     return(NULL);
    294   }
    295   snprintf(s,256, "%e", self->value->value);
    296 
    297   return(s);
    298 }
    299 
    300 internal smallDoublet* duplicateSmallDouble(smallDoublet *self) {
    301 
    302   createAllocateSmallDouble(dup);
    303   if (!dup) {
    304     return(NULL);
    305   }
    306   if (self->value) {
    307     isError(dup->value, allocSDouble(self->value->value)) {
    308       terminateO(dup);
    309       return(NULL);
    310     }
    311   }
    312   return(dup);
    313 }
    314 
    315 internal void  smashSmallDouble(smallDoublet **self) {
    316 
    317   finishSmallDouble(self);
    318 }
    319 
    320 #if (NFreeStackCheck)
    321 internal void finishSmallDouble(smallDoublet **self) {
    322 
    323   register u64 rsp asm("rsp");
    324   if ((u64)*self > rsp) {
    325     logW("Probably trying to free a smallDouble on stack: "BLD PRIx64 RST" sp: "BLD PRIx64 RST, *self, rsp);
    326     logBtrace;
    327   }
    328   else {
    329     #if (recycleContainers)
    330     finishRecycle
    331     #else
    332     free(*self);
    333     #endif
    334     // recycleContainers
    335     *self = NULL;
    336 }
    337   }
    338 
    339 #else
    340 // #if NFreeStackCheck
    341 internal void finishSmallDouble(smallDoublet **self) {
    342 
    343   #if (recycleContainers)
    344   finishRecycle
    345   #else
    346   free(*self);
    347   #endif
    348   // recycleContainers
    349   *self = NULL;
    350 }
    351 
    352 #endif
    353 // #if NFreeStackCheck
    354 
    355 internal const char* helpSmallDouble(smallDoublet UNUSED *self) {
    356 
    357   return(helpTextSmallDouble);
    358 }
    359 
    360 internal double  getSmallDouble(smallDoublet *self) {
    361 
    362   if (!self->value) {
    363     return(0);
    364   }
    365   return(self->value->value);
    366 }
    367 
    368 internal smallDoublet*  setSmallDouble(smallDoublet *self, double value) {
    369 
    370   if (!self->value) {
    371     isError(self->value, allocSDouble(value)) return(NULL);
    372   }
    373   else {
    374     self->value->value = value;
    375   }
    376   return(self);
    377 }
    378 
    379 internal smallDoublet* setBoolSmallDouble(smallDoublet* self, bool p2) {
    380 
    381   if (!self->value) {
    382     isError(self->value, allocSDouble((double)p2)) return(NULL);
    383   }
    384   else {
    385     self->value->value = (double)p2;
    386   }
    387   return(self);
    388 }
    389 
    390 internal smallDoublet* setInt64SmallDouble(smallDoublet* self, int64_t p2) {
    391 
    392   if (!self->value) {
    393     isError(self->value, allocSDouble((double)p2)) return(NULL);
    394   }
    395   else {
    396     self->value->value = (double)p2;
    397   }
    398   return(self);
    399 }
    400 
    401 internal smallDoublet* setInt32SmallDouble(smallDoublet* self, int32_t p2) {
    402 
    403   if (!self->value) {
    404     isError(self->value, allocSDouble((double)p2)) return(NULL);
    405   }
    406   else {
    407     self->value->value = (double)p2;
    408   }
    409   return(self);
    410 }
    411 
    412 internal smallDoublet* setUint32SmallDouble(smallDoublet* self, uint32_t p2) {
    413 
    414   if (!self->value) {
    415     isError(self->value, allocSDouble((double)p2)) return(NULL);
    416   }
    417   else {
    418     self->value->value = (double)p2;
    419   }
    420   return(self);
    421 }
    422 
    423 internal smallDoublet* setUint64SmallDouble(smallDoublet* self, uint64_t p2) {
    424 
    425   if (!self->value) {
    426     isError(self->value, allocSDouble((double)p2)) return(NULL);
    427   }
    428   else {
    429     self->value->value = (double)p2;
    430   }
    431   return(self);
    432 }
    433 
    434 internal smallDoublet* setSSmallDouble(smallDoublet* self, const char* p2) {
    435 
    436   if (!p2 || !isNumber(p2)) {
    437     return(NULL);
    438   }
    439   if (!self->value) {
    440     isError(self->value, allocSDouble(parseDouble(p2))) return(NULL);
    441   }
    442   else {
    443     self->value->value = parseDouble(p2);
    444   }
    445   return(self);
    446 }
    447 
    448 internal smallDoublet* setSmallBoolSmallDouble(smallDoublet* self, smallBoolt* p2) {
    449   bool value;
    450 
    451   if (!p2) {
    452     return(NULL);
    453   }
    454 
    455   value = p2->f->get(p2);
    456 
    457   if (!self->value) {
    458     isError(self->value, allocSDouble((double)value)) return(NULL);
    459   }
    460   else {
    461     self->value->value = (double)value;
    462   }
    463   return(self);
    464 }
    465 
    466 internal smallDoublet* setSmallDoubleSmallDouble(smallDoublet* self, smallDoublet* p2) {
    467 
    468   if (!p2) {
    469     return(NULL);
    470   }
    471 
    472   if (!self->value) {
    473     isError(self->value, allocSDouble(p2->f->get(p2))) return(NULL);
    474   }
    475   else {
    476     self->value->value = p2->f->get(p2);
    477   }
    478   return(self);
    479 }
    480 
    481 internal smallDoublet* setSmallIntSmallDouble(smallDoublet* self, smallIntt* p2) {
    482 
    483   if (!p2) {
    484     return(NULL);
    485   }
    486 
    487   if (!self->value) {
    488     isError(self->value, allocSDouble((double)p2->f->get(p2))) return(NULL);
    489   }
    490   else {
    491     self->value->value = (double)p2->f->get(p2);
    492   }
    493   return(self);
    494 }
    495 
    496 internal smallDoublet* setSmallJsonSmallDouble(smallDoublet* self, smallJsont* p2) {
    497 
    498   if (!p2) {
    499     return(NULL);
    500   }
    501 
    502   const char *type = getTopTypeO(p2);
    503 
    504   if (!type || eqS(type, "undefined") || eqS(type, "dict") || eqS(type, "array")) {
    505     return(NULL);
    506   }
    507 
    508   if (eqS(type, "bool")) {
    509     return(setBoolSmallDouble(self, getTopBoolO(p2)));
    510   }
    511   else if (eqS(type, "double")) {
    512     return(setSmallDouble(self, getTopDoubleO(p2)));
    513   }
    514   else if (eqS(type, "int")) {
    515     return(setInt64SmallDouble(self, getTopIntO(p2)));
    516   }
    517   else if (eqS(type, "string")) {
    518     return(setSSmallDouble(self, getTopSO(p2)));
    519   }
    520   return(NULL);
    521 }
    522 
    523 
    524 internal smallDoublet* setSmallStringSmallDouble(smallDoublet* self, smallStringt* p2) {
    525 
    526   if (!p2 || !isNumberO(p2)) {
    527     return(NULL);
    528   }
    529   if (!self->value) {
    530     isError(self->value, allocSDouble(parseDoubleO(p2))) return(NULL);
    531   }
    532   else {
    533     self->value->value = parseDoubleO(p2);
    534   }
    535   return(self);
    536 }
    537 
    538 internal double* getPSmallDouble(smallDoublet *self) {
    539 
    540   if (!self->value) {
    541     return(NULL);
    542   }
    543   return(&(self->value->value));
    544 }
    545 
    546 internal bool equalSmallDoubleCha(smallDoublet* self, char p2) {
    547 
    548   if (!self->value) {
    549     return(false);
    550   }
    551 
    552   charToS(s, p2);
    553 
    554   if (isInt(s) || !isNumber(s)) {
    555     return(false);
    556   }
    557 
    558   double value = parseDouble(s);
    559 
    560   return(self->value->value == value);;
    561 }
    562 
    563 internal bool equalSmallDoubleChar(smallDoublet* self, const char * p2) {
    564 
    565   if (!self->value || !p2) {
    566     return(false);
    567   }
    568 
    569   if (isInt(p2) || !isNumber(p2)) {
    570     return(false);
    571   }
    572 
    573   double value = parseDouble(p2);
    574 
    575   return(self->value->value == value);;
    576 }
    577 
    578 internal bool equalSmallDoubleBase(smallDoublet* self, baset* p2) {
    579 
    580   if (!self->value || !p2) {
    581     return(false);
    582   }
    583 
    584   char *s = toStringO(p2);
    585 
    586   if (isInt(s) || !isNumber(s)) {
    587     free(s);
    588     return(false);
    589   }
    590 
    591   double value = parseDouble(s);
    592 
    593   bool r;
    594   if (self->value->value == value) {
    595     r = true;
    596   }
    597   else {
    598     r = false;
    599   }
    600 
    601   free(s);
    602   return(r);
    603 }
    604 
    605 internal bool equalSmallDoubleBool(smallDoublet* self, bool p2) {
    606 
    607   if (!self->value) {
    608     return(false);
    609   }
    610 
    611   return(self->value->value == p2);;
    612 }
    613 
    614 internal bool equalSmallDoubleDouble(smallDoublet* self, double p2) {
    615 
    616   if (!self->value) {
    617     return(false);
    618   }
    619 
    620   return(self->value->value == p2);;
    621 }
    622 
    623 internal bool equalSmallDoubleInt64(smallDoublet* self, int64_t p2) {
    624 
    625   if (!self->value) {
    626     return(false);
    627   }
    628 
    629   return(self->value->value == p2);;
    630 }
    631 
    632 internal bool equalSmallDoubleInt32(smallDoublet* self, int32_t p2) {
    633 
    634   if (!self->value) {
    635     return(false);
    636   }
    637 
    638   return(self->value->value == p2);;
    639 }
    640 
    641 internal bool equalSmallDoubleUint32(smallDoublet* self, uint32_t p2) {
    642 
    643   if (!self->value) {
    644     return(false);
    645   }
    646 
    647   return(self->value->value == p2);;
    648 }
    649 
    650 internal bool equalSmallDoubleUint64(smallDoublet* self, uint64_t p2) {
    651 
    652   if (!self->value) {
    653     return(false);
    654   }
    655 
    656   return(self->value->value == p2);;
    657 }
    658 
    659 internal bool equalSmallDoubleSmallBool(smallDoublet* self, smallBoolt* p2) {
    660 
    661   if (!self->value || !p2 || !p2->value) {
    662     return(false);
    663   }
    664 
    665   return(self->value->value == p2->value->value);;
    666 }
    667 
    668 internal bool equalSmallDoubleSmallBytes(smallDoublet* self, smallBytest* p2) {
    669 
    670   if (!self->value || !p2 || !p2->B) {
    671     return(false);
    672   }
    673 
    674   char *s = sBytesGet(p2->B);
    675 
    676   bool has0 = false;
    677   rangeDown(i, p2->B->count) {
    678     if (s[i] == 0) {
    679       has0 = true;
    680       break;
    681     }
    682   }
    683 
    684   if (!has0) {
    685     return(false);
    686   }
    687 
    688   if (isInt(s) || !isNumber(s)) {
    689     return(false);
    690   }
    691 
    692   double p2Value = parseDouble(s);
    693 
    694   return(p2Value == self->value->value);;
    695 }
    696 
    697 
    698 internal bool equalSmallDouble(smallDoublet* self, smallDoublet* p2) {
    699 
    700   if (!self->value || !p2 || !p2->value) {
    701     return(false);
    702   }
    703 
    704   return(self->value->value == p2->value->value);;
    705 }
    706 
    707 internal bool equalSmallDoubleSmallInt(smallDoublet* self, smallIntt* p2) {
    708 
    709   if (!self->value || !p2 || !p2->value) {
    710     return(false);
    711   }
    712 
    713   return(self->value->value == p2->value->value);;
    714 }
    715 
    716 internal bool equalSmallDoubleSmallJson(smallDoublet* self, smallJsont* p2) {
    717 
    718   if (!p2) {
    719     return(false);
    720   }
    721 
    722   if (checkObjectTypes && !isOSmallJson(p2)) {
    723     return(false);
    724   }
    725 
    726   return(p2->f->equalSmallDouble(p2, self));
    727 }
    728 
    729 internal bool equalSmallDoubleSmallString(smallDoublet* self, smallStringt* p2) {
    730 
    731   if (!self->value || !p2 || !p2->data) {
    732     return(false);
    733   }
    734 
    735   if (isIntO(p2) || !isNumberO(p2)) {
    736     return(false);
    737   }
    738 
    739   double value = parseDoubleO(p2);
    740 
    741   return(self->value->value == value);;
    742 }
    743 
    744 internal smallDoublet* readFileSmallDouble(smallDoublet *self, const char *filePath) {
    745   FILE *f = NULL;
    746   size_t readStatus;
    747 
    748   // sanity checks
    749   if (!filePath || isBlankS(filePath)) {
    750     return(NULL);
    751   }
    752 
    753   if (!self->value) {
    754     isError(self->value, allocSDouble(0)) return(NULL);
    755   }
    756 
    757   f = fopen(filePath, "r");
    758   if (!f) {
    759     pFuncError
    760     shEPrintfS("The path was: \"%s\"\n", filePath);
    761     return(NULL);
    762   }
    763   readStatus = fread(&self->value->value, 1, sizeof(double) , f);
    764   fclose(f);
    765 
    766   if (readStatus != sizeof(double)) {
    767     pFuncError
    768     shEPrintfS("The path was: \"%s\"\n", filePath);
    769     return(NULL);
    770   }
    771 
    772   return(self);
    773 }
    774 
    775 internal smallDoublet* readFileSmallJsonSmallDouble(smallDoublet *self, smallJsont *filePath) {
    776 
    777   if (!filePath) {
    778     return(NULL);
    779   }
    780 
    781   if (checkObjectTypes && !isOSmallJson(filePath)) {
    782     return(NULL);
    783   }
    784 
    785   const char *type = getTopTypeO(filePath);
    786 
    787   if (!eqS(type,"string")) {
    788     return(NULL);
    789   }
    790 
    791   return(readFileSmallDouble(self, getTopSO(filePath)));
    792 }
    793 
    794 internal smallDoublet* readFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath) {
    795 
    796   if (!filePath) {
    797     return(NULL);
    798   }
    799 
    800   if (checkObjectTypes && !isOSmallString(filePath)) {
    801     return(NULL);
    802   }
    803 
    804   return(readFileSmallDouble(self, ssGet(filePath)));
    805 }
    806 
    807 internal smallDoublet* readStreamSmallDouble(smallDoublet *self, FILE *fp) {
    808   size_t readStatus;
    809 
    810   // sanity checks
    811   if (!fp) {
    812     return(NULL);
    813   }
    814 
    815   if (!self->value) {
    816     isError(self->value, allocSDouble(0)) return(NULL);
    817   }
    818 
    819   readStatus = fread(&self->value->value, 1, sizeof(double) , fp);
    820 
    821   if (readStatus != sizeof(double)) {
    822     pFuncError
    823     return(NULL);
    824   }
    825 
    826   return(self);
    827 }
    828 
    829 internal int writeFileSmallDouble(smallDoublet *self, const char *filePath) {
    830   FILE *f = NULL;
    831   size_t writeStatus;
    832 
    833   // sanity checks
    834   if (!filePath || isBlankS(filePath) || !self->value) {
    835     return(0);
    836   }
    837 
    838   f = fopen(filePath, "w");
    839   if (!f) {
    840     pFuncError
    841     shEPrintfS("The path was: \"%s\"\n", filePath);
    842     return(0);
    843   }
    844   writeStatus = fwrite(&self->value->value, 1, sizeof(double) , f);
    845   fclose(f);
    846 
    847   if (writeStatus != sizeof(double)) {
    848     pFuncError
    849     shEPrintfS("The path was: \"%s\"\n", filePath);
    850     return(0);
    851   }
    852 
    853   return(1);
    854 }
    855 
    856 internal int writeFileSmallJsonSmallDouble(smallDoublet *self, smallJsont *filePath) {
    857 
    858   if (!filePath) {
    859     return(0);
    860   }
    861 
    862   if (checkObjectTypes && !isOSmallJson(filePath)) {
    863     return(0);
    864   }
    865 
    866   const char *type = getTopTypeO(filePath);
    867 
    868   if (!eqS(type,"string")) {
    869     return(0);
    870   }
    871 
    872   return(writeFileSmallDouble(self, getTopSO(filePath)));
    873 }
    874 
    875 internal int writeFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath) {
    876 
    877   if (!filePath) {
    878     return(0);
    879   }
    880 
    881   if (checkObjectTypes && !isOSmallString(filePath)) {
    882     return(0);
    883   }
    884 
    885   return(writeFileSmallDouble(self, ssGet(filePath)));
    886 }
    887 
    888 internal int writeStreamSmallDouble(smallDoublet *self, FILE *fp) {
    889   size_t writeStatus;
    890 
    891   // sanity checks
    892   if (!fp || !self->value) {
    893     return(0);
    894   }
    895 
    896   writeStatus = fwrite(&self->value->value, 1, sizeof(double) , fp);
    897 
    898   if (writeStatus != sizeof(double)) {
    899     pFuncError
    900     return(0);
    901   }
    902 
    903   return(1);
    904 }
    905 
    906 internal int appendFileSmallDouble(smallDoublet *self, const char *filePath) {
    907   FILE *f = NULL;
    908   size_t writeStatus;
    909 
    910   // sanity checks
    911   if (!filePath || isBlankS(filePath) || !self->value) {
    912     return(0);
    913   }
    914 
    915   f = fopen(filePath, "a");
    916   if (!f) {
    917     pFuncError
    918     shEPrintfS("The path was: \"%s\"\n", filePath);
    919     return(0);
    920   }
    921   writeStatus = fwrite(&self->value->value, 1, sizeof(double) , f);
    922   fclose(f);
    923 
    924   if (writeStatus != sizeof(double)) {
    925     pFuncError
    926     shEPrintfS("The path was: \"%s\"\n", filePath);
    927     return(0);
    928   }
    929 
    930   return(1);
    931 }
    932 
    933 internal int appendFileSmallStringSmallDouble(smallDoublet *self, smallStringt *filePath) {
    934 
    935   if (!filePath) {
    936     return(0);
    937   }
    938   return(appendFileSmallDouble(self, ssGet(filePath)));
    939 }
    940 
    941 
    942 
    943 smallDoublet*      duplicateSmallDoubleG          (smallDoublet *self) {
    944 
    945   return(self->f->duplicate(self));
    946 }
    947 
    948 void               freeSmallDoubleG               (smallDoublet *self) {self->f->free(self);}
    949 
    950 double             getDoubleSmallDoubleG          (smallDoublet *self, double retType UNUSED, int64_t index UNUSED) {
    951 
    952   return(self->f->get(self));
    953 }
    954 
    955 smallDoublet* setBoolSmallDoubleG(smallDoublet* self, bool p2) {
    956 
    957   return(self->f->setBool(self, p2));
    958 }
    959 
    960 smallDoublet* setSmallDoubleG(smallDoublet* self, double p2) {
    961 
    962   return(self->f->set(self, p2));
    963 }
    964 
    965 smallDoublet* setInt64SmallDoubleG(smallDoublet* self, int64_t p2) {
    966 
    967   return(self->f->setInt64(self, p2));
    968 }
    969 
    970 smallDoublet* setInt32SmallDoubleG(smallDoublet* self, int32_t p2) {
    971 
    972   return(self->f->setInt32(self, p2));
    973 }
    974 
    975 smallDoublet* setUint32SmallDoubleG(smallDoublet* self, uint32_t p2) {
    976 
    977   return(self->f->setUint32(self, p2));
    978 }
    979 
    980 smallDoublet* setUint64SmallDoubleG(smallDoublet* self, uint64_t p2) {
    981 
    982   return(self->f->setUint64(self, p2));
    983 }
    984 
    985 smallDoublet* setSSmallDoubleG(smallDoublet* self, const char* p2) {
    986 
    987   return(self->f->setS(self, p2));
    988 }
    989 
    990 smallDoublet* setSmallBoolSmallDoubleG(smallDoublet* self, smallBoolt* p2) {
    991 
    992   return(self->f->setSmallBool(self, p2));
    993 }
    994 
    995 smallDoublet* setSmallDoubleSmallDoubleG(smallDoublet* self, smallDoublet* p2) {
    996 
    997   return(self->f->setSmallDouble(self, p2));
    998 }
    999 
   1000 smallDoublet* setSmallIntSmallDoubleG(smallDoublet* self, smallIntt* p2) {
   1001 
   1002   return(self->f->setSmallInt(self, p2));
   1003 }
   1004 
   1005 smallDoublet* setSmallJsonSmallDoubleG(smallDoublet* self, smallJsont* p2) {
   1006 
   1007   return(self->f->setSmallJson(self, p2));
   1008 }
   1009 
   1010 smallDoublet* setSmallStringSmallDoubleG(smallDoublet* self, smallStringt* p2) {
   1011 
   1012   return(self->f->setSmallString(self, p2));
   1013 }
   1014 
   1015 
   1016 double*            getDoublePSmallDoubleG         (smallDoublet *self, double* retType UNUSED, int64_t index UNUSED) {
   1017 
   1018   return(self->f->getP(self));
   1019 }
   1020 
   1021 bool equalSmallDoubleChaG(smallDoublet* self, char p2) {
   1022 
   1023   return(self->f->equalCha(self, p2));
   1024 }
   1025 
   1026 bool equalSmallDoubleCharG(smallDoublet* self, const char * p2) {
   1027 
   1028   return(self->f->equalChar(self, p2));
   1029 }
   1030 
   1031 bool equalSmallDoubleBaseG(smallDoublet* self, baset* p2) {
   1032 
   1033   return(self->f->equalBase(self, p2));
   1034 }
   1035 
   1036 bool equalSmallDoubleBoolG(smallDoublet* self, bool p2) {
   1037 
   1038   return(self->f->equalBool(self, p2));
   1039 }
   1040 
   1041 bool equalSmallDoubleDoubleG(smallDoublet* self, double p2) {
   1042 
   1043   return(self->f->equalDouble(self, p2));
   1044 }
   1045 
   1046 bool equalSmallDoubleInt64G(smallDoublet* self, int64_t p2) {
   1047 
   1048   return(self->f->equalInt64(self, p2));
   1049 }
   1050 
   1051 bool equalSmallDoubleInt32G(smallDoublet* self, int32_t p2) {
   1052 
   1053   return(self->f->equalInt32(self, p2));
   1054 }
   1055 
   1056 bool equalSmallDoubleUint32G(smallDoublet* self, uint32_t p2) {
   1057 
   1058   return(self->f->equalUint32(self, p2));
   1059 }
   1060 
   1061 bool equalSmallDoubleUint64G(smallDoublet* self, uint64_t p2) {
   1062 
   1063   return(self->f->equalUint64(self, p2));
   1064 }
   1065 
   1066 bool equalSmallDoubleSmallBoolG(smallDoublet* self, smallBoolt* p2) {
   1067 
   1068   return(self->f->equalSmallBool(self, p2));
   1069 }
   1070 
   1071 bool equalSmallDoubleSmallBytesG(smallDoublet* self, smallBytest* p2) {
   1072 
   1073   return(self->f->equalSmallBytes(self, p2));
   1074 }
   1075 
   1076 bool equalSmallDoubleFG(smallDoublet* self, smallDoublet* p2) {
   1077 
   1078   return(self->f->equal(self, p2));
   1079 }
   1080 
   1081 bool equalSmallDoubleSmallIntG(smallDoublet* self, smallIntt* p2) {
   1082 
   1083   return(self->f->equalSmallInt(self, p2));
   1084 }
   1085 
   1086 bool equalSmallDoubleSmallJsonG(smallDoublet* self, smallJsont* p2) {
   1087 
   1088   return(self->f->equalSmallJson(self, p2));
   1089 }
   1090 
   1091 bool equalSmallDoubleSmallStringG(smallDoublet* self, smallStringt* p2) {
   1092 
   1093   return(self->f->equalSmallString(self, p2));
   1094 }
   1095 
   1096 smallDoublet*  readFileSmallDoubleG     (smallDoublet *self, const char *filePath) {
   1097 
   1098   return(self->f->readFile(self, filePath));
   1099 }
   1100 
   1101 smallDoublet* readFileSmallJsonSmallDoubleG  (smallDoublet *self, smallJsont *filePath) {
   1102 
   1103   return(self->f->readFileSmallJson(self,filePath));
   1104 }
   1105 
   1106 smallDoublet* readFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath) {
   1107 
   1108   return(self->f->readFileSmallString(self,filePath));
   1109 }
   1110 
   1111 smallDoublet* readStreamSmallDoubleG         (smallDoublet *self, FILE *fp) {
   1112 
   1113   return(self->f->readStream(self, fp));
   1114 }
   1115 
   1116 int  writeFileSmallDoubleG    (smallDoublet *self, const char *filePath) {
   1117 
   1118   return(self->f->writeFile(self, filePath));
   1119 }
   1120 
   1121 int writeFileSmallJsonSmallDoubleG  (smallDoublet *self, smallJsont *filePath) {
   1122 
   1123   return(self->f->writeFileSmallJson(self,filePath));
   1124 }
   1125 
   1126 int writeFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath) {
   1127 
   1128   return(self->f->writeFileSmallString(self,filePath));
   1129 }
   1130 
   1131 int writeStreamSmallDoubleG         (smallDoublet *self, FILE *fp) {
   1132 
   1133   return(self->f->writeStream(self, fp));
   1134 }
   1135 
   1136 int appendFileSmallDoubleFG           (smallDoublet *self, const char *filePath) {
   1137 
   1138   return(self->f->appendFile(self, filePath));
   1139 }
   1140 
   1141 int appendFileSmallStringSmallDoubleG(smallDoublet *self, smallStringt *filePath) {
   1142 
   1143   return(self->f->appendFileSmallString(self,filePath));
   1144 }
   1145