LCOV - code coverage report
Current view: top level - clients/examples/C - bincopydecimal_impl.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 23 87.0 %
Date: 2024-04-25 20:03:45 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : void
      14           4 : FUNCNAME(FILE *f, bool byteswap, long nrecs, char *arg)
      15             : {
      16           4 :         if (!arg)
      17           0 :                 croak(2, "this generator needs a scale argument");
      18             : 
      19           4 :         char *end = NULL;
      20           4 :         int scale = (int)strtol(arg, &end, 10);
      21           4 :         if (*arg == '\0' || *end != '\0')
      22           0 :                 croak(2, "invalid scale argument");
      23             :         STYP hi = 1;
      24          23 :         while (scale-- > 0)
      25          19 :                 hi *= 10;
      26           4 :         hi -= 1;
      27             : 
      28           4 :         STYP n = 0;
      29     4000004 :         for (long i = 0; i < nrecs; i++) {
      30     4000000 :                 STYP svalue = n / 2;
      31     4000000 :                 if (i % 2 != 0)
      32     2000000 :                         svalue = -svalue;
      33     4000000 :                 UTYP uvalue = (UTYP) svalue;
      34             : #ifdef CONVERT
      35     3000000 :                 if (byteswap)
      36           0 :                         CONVERT(&uvalue);
      37             : #else
      38     1000000 :                 (void)byteswap;
      39             : #endif
      40     4000000 :                 fwrite(&uvalue, sizeof(uvalue), 1, f);
      41             : 
      42     4000000 :                 if (n == 2 * hi + 1)
      43             :                         n = 0;
      44             :                 else
      45     3949495 :                         n++;
      46             :         }
      47           4 : }
      48             : 
      49             : #undef FUNCNAME
      50             : #undef STYP
      51             : #undef UTYP
      52             : #undef CONVERT

Generated by: LCOV version 1.14