|
3 | 3 | #include<errno.h>
|
4 | 4 | #include<math.h>
|
5 | 5 | #include<ctype.h>
|
| 6 | +#include<limits.h> |
6 | 7 |
|
7 | 8 | #include<ecpgtype.h>
|
8 | 9 | #include<compatlib.h>
|
|
11 | 12 | #include<pgtypes_numeric.h>
|
12 | 13 | #include<sqltypes.h>
|
13 | 14 |
|
14 |
| -char*ECPGalloc(long,int); |
| 15 | +char*ECPGalloc(long,int); |
15 | 16 |
|
16 | 17 | staticint
|
17 | 18 | deccall2(decimal*arg1,decimal*arg2,int (*ptr) (numeric*,numeric*))
|
@@ -659,41 +660,50 @@ static struct
|
659 | 660 | }value;
|
660 | 661 |
|
661 | 662 | /**
|
662 |
| - * initialize the struct,wich holds the different forms |
| 663 | + * initialize the struct,which holds the different forms |
663 | 664 | * of the long value
|
664 | 665 | */
|
665 | 666 | staticvoid
|
666 |
| -initValue(longlng_val) |
667 |
| -{ |
668 |
| -inti, |
669 |
| -div, |
670 |
| -dig; |
671 |
| -chartmp[2]=" "; |
672 |
| - |
673 |
| -/* set some obvious things */ |
674 |
| -value.val=lng_val >=0 ?lng_val :lng_val* (-1); |
675 |
| -value.sign=lng_val >=0 ?'+' :'-'; |
676 |
| -value.maxdigits=log10(2)* (8*sizeof(long)-1); |
677 |
| - |
678 |
| -/* determine the number of digits */ |
679 |
| -for (i=0;i <=value.maxdigits;i++) |
680 |
| -{ |
681 |
| -if ((int) (value.val /pow(10,i))!=0) |
682 |
| -value.digits=i+1; |
683 |
| -} |
684 |
| -value.remaining=value.digits; |
685 |
| - |
686 |
| -/* convert the long to string */ |
687 |
| -value.val_string= (char*)malloc(value.digits+1); |
688 |
| -for (i=value.digits;i>0;i--) |
689 |
| -{ |
690 |
| -div=pow(10,i); |
691 |
| -dig= (value.val %div) / (div /10); |
692 |
| -tmp[0]= (char) (dig+48); |
693 |
| -strcat(value.val_string,tmp); |
694 |
| -} |
695 |
| -/* safety-net */ |
696 |
| -value.val_string[value.digits]='\0'; |
| 667 | +initValue (longlng_val) |
| 668 | +{ |
| 669 | +inti,j; |
| 670 | +longl,dig; |
| 671 | + |
| 672 | +/* set some obvious things */ |
| 673 | +value.val=lng_val >=0 ?lng_val :lng_val* (-1); |
| 674 | +value.sign=lng_val >=0 ?'+' :'-'; |
| 675 | +value.maxdigits=log10 (2)* (8*sizeof (long)-1); |
| 676 | + |
| 677 | +/* determine the number of digits */ |
| 678 | +i=0; |
| 679 | +l=1; |
| 680 | +do |
| 681 | + { |
| 682 | +i++; |
| 683 | +l *=10; |
| 684 | + } |
| 685 | +while ((l-1)<value.val&&l <=LONG_MAX /10); |
| 686 | + |
| 687 | +if (l <=LONG_MAX/10) |
| 688 | + { |
| 689 | +value.digits=i; |
| 690 | +l /=10; |
| 691 | + } |
| 692 | +else |
| 693 | +value.digits=i+1; |
| 694 | + |
| 695 | +value.remaining=value.digits; |
| 696 | + |
| 697 | +/* convert the long to string */ |
| 698 | +value.val_string= (char*)malloc (value.digits+1); |
| 699 | +dig=value.val; |
| 700 | +for (i=value.digits,j=0;i>0;i--,j++) |
| 701 | + { |
| 702 | +value.val_string[j]=dig/l+'0'; |
| 703 | +dig=dig %l; |
| 704 | +l /=10; |
| 705 | + } |
| 706 | +value.val_string[value.digits]='\0'; |
697 | 707 | }
|
698 | 708 |
|
699 | 709 | /* return the position oft the right-most dot in some string */
|
|