/[dtapublic]/projs/trunk/shared_source/c_datd/esrg_int_def.c
ViewVC logotype

Diff of /projs/trunk/shared_source/c_datd/esrg_int_def.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 70 by dashley, Sat Oct 29 01:53:01 2016 UTC revision 71 by dashley, Sat Nov 5 11:07:06 2016 UTC
# Line 1  Line 1 
1  //$Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components  //This file is part of "David T. Ashley's Shared Source Code", a set of shared components
4  //integrated into many of David T. Ashley's projects.  //integrated into many of David T. Ashley's projects.
5  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
6  //This source code and any program in which it is compiled/used is provided under the MIT License,  //This source code and any program in which it is compiled/used is provided under the MIT License,
7  //reproduced below.  //reproduced below.
8  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
9  //Permission is hereby granted, free of charge, to any person obtaining a copy of  //Permission is hereby granted, free of charge, to any person obtaining a copy of
10  //this software and associated documentation files(the "Software"), to deal in the  //this software and associated documentation files(the "Software"), to deal in the
11  //Software without restriction, including without limitation the rights to use,  //Software without restriction, including without limitation the rights to use,
12  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  //copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
13  //Software, and to permit persons to whom the Software is furnished to do so,  //Software, and to permit persons to whom the Software is furnished to do so,
14  //subject to the following conditions :  //subject to the following conditions :
15  //  //
16  //The above copyright notice and this permission notice shall be included in all  //The above copyright notice and this permission notice shall be included in all
17  //copies or substantial portions of the Software.  //copies or substantial portions of the Software.
18  //  //
19  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
22  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  //SOFTWARE.  //SOFTWARE.
26  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
27  #define MODULE_ESRG_INT_DEF  #define MODULE_ESRG_INT_DEF
28    
29  #include <assert.h>  #include <assert.h>
30  #include <string.h>  #include <string.h>
31    
32  #include "esrg_int_def.h"  #include "esrg_int_def.h"
33    
34    
35  void ESRG_INT_DEF_Create( ESRG_INT_DEF_INT *arg, int is_signed )  void ESRG_INT_DEF_Create( ESRG_INT_DEF_INT *arg, int is_signed )
36     {     {
37     assert(arg != NULL);     assert(arg != NULL);
38    
39     memset(arg, 0, sizeof(ESRG_INT_DEF_INT));     memset(arg, 0, sizeof(ESRG_INT_DEF_INT));
40    
41     if (is_signed)     if (is_signed)
42        {        {
43        arg->flags = ESRG_INT_DEF_FLAG_IS_SIGNED;        arg->flags = ESRG_INT_DEF_FLAG_IS_SIGNED;
44        }        }
45     }     }
46    
47    
48  void ESRG_INT_DEF_AssignU( ESRG_INT_DEF_INT *arg, unsigned int aval)  void ESRG_INT_DEF_AssignU( ESRG_INT_DEF_INT *arg, unsigned int aval)
49     {     {
50     assert(arg != NULL);     assert(arg != NULL);
51    
52     //Reset any pending error flags.  An assignment starts fresh.     //Reset any pending error flags.  An assignment starts fresh.
53     arg->flags &= ~(ESRG_INT_DEF_FLAG_NEG_ROLL | ESRG_INT_DEF_FLAG_POS_ROLL | ESRG_INT_DEF_FLAG_NAN);     arg->flags &= ~(ESRG_INT_DEF_FLAG_NEG_ROLL | ESRG_INT_DEF_FLAG_POS_ROLL | ESRG_INT_DEF_FLAG_NAN);
54    
55     arg->limbs[0] = aval;     arg->limbs[0] = aval;
56     memset(&(arg->limbs[1]), 0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));     memset(&(arg->limbs[1]), 0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));
57    
58     //The only circumstance under which there is an overflow     //The only circumstance under which there is an overflow
59     //is if the value is inherently signed and if the limbs per     //is if the value is inherently signed and if the limbs per
60     //int is 1 and the MSB is set.     //int is 1 and the MSB is set.
61     if (arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED)     if (arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED)
62        {        {
63        if (ESRG_INT_DEF_NLIMBS == 1)        if (ESRG_INT_DEF_NLIMBS == 1)
64           {           {
65           if (aval & (1 << (ESRG_INT_DEF_NATIVE_BITSIZE-1)))           if (aval & (1 << (ESRG_INT_DEF_NATIVE_BITSIZE-1)))
66              {              {
67              arg->flags |= ESRG_INT_DEF_FLAG_POS_ROLL;              arg->flags |= ESRG_INT_DEF_FLAG_POS_ROLL;
68              }              }
69           }           }
70        }        }
71     }     }
72    
73    
74  void ESRG_INT_DEF_AssignS( ESRG_INT_DEF_INT *arg, int aval)  void ESRG_INT_DEF_AssignS( ESRG_INT_DEF_INT *arg, int aval)
75     {     {
76     assert(arg != NULL);     assert(arg != NULL);
77    
78     //Reset any pending error flags.  An assignment starts fresh.     //Reset any pending error flags.  An assignment starts fresh.
79     arg->flags &= ~(ESRG_INT_DEF_FLAG_NEG_ROLL | ESRG_INT_DEF_FLAG_POS_ROLL | ESRG_INT_DEF_FLAG_NAN);     arg->flags &= ~(ESRG_INT_DEF_FLAG_NEG_ROLL | ESRG_INT_DEF_FLAG_POS_ROLL | ESRG_INT_DEF_FLAG_NAN);
80    
81     arg->limbs[0] = aval;     arg->limbs[0] = aval;
82        //Assign the base limb.        //Assign the base limb.
83    
84     //Deal with the sign extension.  If the number is not signed,     //Deal with the sign extension.  If the number is not signed,
85     //don't extend at all.  If the number is signed, extend.     //don't extend at all.  If the number is signed, extend.
86     if (arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED)     if (arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED)
87        {        {
88        if (aval < 0)        if (aval < 0)
89           memset(&(arg->limbs[1]), -1, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));           memset(&(arg->limbs[1]), -1, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));
90        else        else
91           memset(&(arg->limbs[1]),  0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));           memset(&(arg->limbs[1]),  0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));
92        }        }
93     else     else
94        {        {
95        memset(&(arg->limbs[1]),  0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));        memset(&(arg->limbs[1]),  0, sizeof(arg->limbs[0]) * (ESRG_INT_DEF_NLIMBS-1));
96        }        }
97        
98     //The only circumstance under which there is an overflow     //The only circumstance under which there is an overflow
99     //is if the value is inherently unsigned and if the limbs per     //is if the value is inherently unsigned and if the limbs per
100     //int is 1 and the MSB is set.     //int is 1 and the MSB is set.
101     if (!(arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED))     if (!(arg->flags & ESRG_INT_DEF_FLAG_IS_SIGNED))
102        {        {
103        if (ESRG_INT_DEF_NLIMBS == 1)        if (ESRG_INT_DEF_NLIMBS == 1)
104           {           {
105           if (aval & (1 << (ESRG_INT_DEF_NATIVE_BITSIZE-1)))           if (aval & (1 << (ESRG_INT_DEF_NATIVE_BITSIZE-1)))
106              {              {
107              arg->flags |= ESRG_INT_DEF_FLAG_POS_ROLL;              arg->flags |= ESRG_INT_DEF_FLAG_POS_ROLL;
108              }              }
109           }           }
110        }        }
111     }     }
112    
113    
114  int ESRG_INT_DEF_Cmp ( ESRG_INT_DEF_INT *a, ESRG_INT_DEF_INT *b )  int ESRG_INT_DEF_Cmp ( ESRG_INT_DEF_INT *a, ESRG_INT_DEF_INT *b )
115     {     {
116     assert(a != NULL);     assert(a != NULL);
117     assert(b != NULL);     assert(b != NULL);
118    
119     return(0);     return(0);
120     }     }
121    
122  //End of esrg_int_def.c.  //End of esrg_int_def.c.

Legend:
Removed from v.70  
changed lines
  Added in v.71

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25