- メインページ
- モジュール
- ネームスペース
- データ構造
- ファイル

- ファイル一覧
- グローバル

integer.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28
33 #ifndef __INCLUDE_MIST_INTEGER_H__
34 #define __INCLUDE_MIST_INTEGER_H__
35
36
37 #ifndef __INCLUDE_MIST_CONF_H__
38 #include "mist_conf.h"
39 #endif
40
41 #include <iostream>
42 #include <string>
43 #include <cstring>
44
45 #include <stdlib.h>
46
47 // mist名前空間の始まり
48 _MIST_BEGIN
49
50 // 以下のコードは Tomy 氏が http://www5.airnet.ne.jp/tomy/cpro/csource.htm にて
51 // 掲載しているソースを参考にして作成し，演算ミス等のバグを修正し，独自の拡張を施したものである．
52 // 基底は256であり，無駄なビットが発生しないようにしてある
53 // integer< 10 > が表現できる数は，-256^10 以上 256^10 未満の整数となる
54 // つまり，-1208925819614629174706176 <= x <= 1208925819614629174706176
55 // 10進の桁数で約24桁程度表現可能となる
56
57
58 template < unsigned int __256_N__ >
59 class integer
60 {
61 public:
62 typedef size_t size_type;
63 typedef ptrdiff_t difference_type;
64 typedef unsigned char value_type;
65
66 private:
67 _MIST_CONST( difference_type, BASE, 256 );
68 _MIST_CONST( size_type, DATA_NUM, __256_N__ );
69
70 protected:
71 size_t length_;
72 bool sign_;
73 value_type data_[ DATA_NUM ];
74
75 public:
76 integer( ) : length_( 0 ), sign_( true )
77 {
78 memset( data_, 0, sizeof( value_type ) * DATA_NUM );
79 }
80
81 integer( difference_type v ) : length_( 0 ), sign_( true )
82 {
83 memset( data_, 0, sizeof( value_type ) * DATA_NUM );
84 if( v != 0 )
85 {
86 if( v < 0 )
87 {
88 sign_ = false;
89 v = -v;
90 }
91 length_ = 0;
92 do
93 {
94 data_[ length_++ ] = static_cast< value_type >( v % BASE );
95 v /= BASE;
96 } while( v > 0 && length_ < DATA_NUM );
97 }
98 }
99
100 integer( const integer &v ) : length_( v.length_ ), sign_( v.sign_ )
101 {
102 memcpy( data_, v.data_, sizeof( value_type ) * DATA_NUM );
103 }
104
105 integer( const ::std::string &str ) : length_( 0 ), sign_( true )
106 {
107 operator =( read( str ) );
108 }
109
110 const integer &operator =( const integer &a )
111 {
112 if( &a != this )
113 {
114 sign_ = a.sign_;
115 length_ = a.length_;
116 memcpy( data_, a.data_, sizeof( value_type ) * DATA_NUM );
117 }
118
119 return ( *this );
120 }
121
122 const integer operator -( ) const
123 {
124 integer x( *this );
125 x.sign_ = !x.sign_;
126 return( x );
127 }
128
129 const integer &operator +=( const integer &a )
130 {
131 if( length_ == 0 )
132 {
133 return ( operator =( a ) );
134 }
135 else if( a.length_ == 0 )
136 {
137 return ( *this );
138 }
139 else
140 {
141 if( sign_ == a.sign_ )
142 {
143 aadd( *this, a );
144 }
145 else
146 {
147 sign_ = asub( *this, a ) ? sign_ : !sign_;
148 }
149 return( *this );
150 }
151 }
152
153 const integer &operator -=( const integer &a )
154 {
155 if( length_ == 0 )
156 {
157 operator =( a );
158 sign_ = !a.sign_;
159 return( *this );
160 }
161 else if( a.length_ == 0 )
162 {
163 return ( *this );
164 }
165 else
166 {
167 if( sign_ == a.sign_ )
168 {
169 sign_ = asub( *this, a ) ? sign_ : !sign_;
170 }
171 else
172 {
173 aadd( *this, a );
174 }
175 return( *this );
176 }
177 }
178
179 const integer &operator *=( const integer &a )
180 {
181 if( length_ * a.length_ == 0 )
182 {
183 return( operator =( integer( 0 ) ) );
184 }
185 else if( length_ == 1 )
186 {
187 difference_type t = sign_ ? data_[ 0 ] : -data_[ 0 ];
188 return( operator =( integer( a ) *= t ) );
189 }
190 else if( a.length_ == 1 )
191 {
192 difference_type t = a.sign_ ? a.data_[ 0 ] : -a.data_[ 0 ];
193 return( operator *=( t ) );
194 }
195
196 if( length_ + a.length_ > DATA_NUM )
197 {
198 // オーバーフロー
199 std::cerr << "overflow!!" << std::endl;
200 return( *this );
201 }
202
203 if( a.length_ > length_ )
204 {
205 return( operator =( integer( a ) *= *this ) );
206 }
207
208 integer x( 0 );
209 x.sign_ = sign_ == a.sign_;
210
211 size_type i;
212 for( size_type j = 0 ; j < a.length_ ; j++ )
213 {
214 difference_type u = a.data_[ j ];
215 if( u != 0 )
216 {
217 difference_type t = 0;
218 size_type imax = length_ + j - 1;
219 for( i = j ; i <= imax ; i++ )
220 {
221 t += ( x.data_[ i ] + u * data_[ i - j ] );
222 x.data_[ i ] = static_cast< value_type >( t % BASE );
223 t /= BASE;
224 }
225 t += x.data_[ i ];
226 while( t >= BASE )
227 {
228 x.data_[ i++ ] = static_cast< value_type >( t - BASE );
229 t = x.data_[ i ] + 1;
230 }
231 x.data_[ i ] = static_cast< value_type >( t );
232 }
233 }
234 x.length_ = length_ + a.length_;
235 while( x.data_[ x.length_ - 1 ] == 0 )
236 {
237 x.length_--;
238 }
239 return( operator =( x ) );
240 }
241
242 const integer &operator *=( difference_type n )
243 {
244 if( length_ == 0 || n == 0 )
245 {
246 return( operator =( integer( 0 ) ) );
247 }
248 // else if( ::std::abs( static_cast< int >( n ) ) >= BASE )
249 else if( n >= BASE || -n >= BASE )
250 {
251 return( operator *=( integer( n ) ) );
252 }
253
254 if( n < 0 )
255 {
256 sign_ = !sign_;
257 n = - n;
258 }
259
260 difference_type t = 0;
261 for( size_type i = 0 ; i < length_ ; i++ )
262 {
263 t += data_[ i ] * n;
264 data_[ i ] = static_cast< value_type >( t % BASE );
265 t /= BASE;
266 }
267
268 while( t != 0 )
269 {
270 length_++;
271 if( length_ > DATA_NUM )
272 {
273 // オーバーフロー
274 std::cerr << "overflow!!" << std::endl;
275 length_--;
276 return( *this );
277 }
278 data_[ length_ - 1 ] = static_cast< value_type >( t % BASE );
279 t /= BASE;
280 }
281 return( *this );
282 }
283
284
285 const integer &operator /=( const integer &a )
286 {
287 if( length_ == 0 )
288 {
289 return( operator =( integer( 0 ) ) );
290 }
291 else if( a.length_ == 0 )
292 {
293 // ゼロ除算
294 std::cerr << "zero division!!" << std::endl;
295 return( *this );
296 }
297 if( a.length_ == 1 )
298 {
299 value_type t = a.sign_ ? a.data_[ 0 ] : -a.data_[ 0 ];
300 return( operator /=( t ) );
301 }
302
303 int c = acmp( *this, a );
304 if( c < 0 )
305 {
306 // 割る数のほうが割られる数より大きいため0にする
307 return( operator =( integer( 0 ) ) );
308 }
309 else if( c == 0 )
310 {
311 // 割る数と割られる数が等しいので1とし，符号のみ設定する
312 return( operator =( integer( sign_ == a.sign_ ? 1 : -1 ) ) );
313 }
314
315 if( length_ == DATA_NUM )
316 {
317 // 割られる数が大きすぎるため除算できない
318 std::cerr << "too large to divide!!" << std::endl;
319 return( *this );
320 }
321
322 integer q, w;
323 integer aa( *this ), bb( a );
324 difference_type d = BASE / ( a.data_[ a.length_ - 1 ] + 1 ), x;
325 q.sign_ = sign_ == a.sign_;
326
327 if( d != 1 )
328 {
329 aa *= d;
330 bb *= d;
331 }
332 q.length_ = aa.length_ - bb.length_ + 1;
333 if( ( x = aa.data_[ aa.length_ - 1 ] / bb.data_[ bb.length_ - 1 ] ) == 0 )
334 {
335 q.length_--;
336 x = ( aa.data_[ aa.length_ - 1 ] * BASE + aa.data_[ aa.length_ - 2 ] ) / bb.data_[ bb.length_ - 1 ];
337 }
338 aa.sign_ = bb.sign_;
339 w.length_ = 0;
340
341 difference_type ql = q.length_;
342 for( ; ; )
343 {
344 for( ; ; )
345 {
346 w = bb * x;
347 shift_up( w, ql - 1 );
348 if( acmp( w, aa ) <= 0 )
349 {
350 break;
351 }
352 x--;
353 }
354 q.data_[ ql-- - 1 ] = static_cast< value_type >( x );
355 aa -= w;
356 if( aa.length_ == 0 || ql == 0 )
357 {
358 break;
359 }
360 x = ( aa.data_[ aa.length_ - 1 ] * BASE + aa.data_[ aa.length_ - 2 ] ) / bb.data_[ bb.length_ - 1 ];
361 }
362 if( q.data_[ q.length_ - 1 ] == 0 )
363 {
364 q.length_--;
365 }
366 return( operator =( q ) );
367 }
368
369 const integer &operator /=( difference_type n )
370 {
371 if( length_ == 0 )
372 {
373 return( *this );
374 }
375 else if( n == 0 )
376 {
377 // ゼロ除算
378 std::cerr << "zero division!!" << std::endl;
379 return( *this );
380 }
381 // else if( ::std::abs( static_cast< int >( n ) ) >= BASE )
382 else if( n >= BASE || -n >= BASE )
383 {
384 return( operator /=( integer( n ) ) );
385 }
386
387 if( n < 0 )
388 {
389 sign_ = !sign_;
390 n = - n;
391 }
392
393 difference_type t = 0;
394 for( difference_type i = length_ - 1 ; i >= 0 ; i-- )
395 {
396 t = t * BASE + data_[ i ];
397 data_[ i ] = static_cast< value_type >( t / n );
398 t %= n;
399 }
400 if( data_[ length_ - 1 ] == 0 )
401 {
402 length_--;
403 }
404 return( *this );
405 }
406
407 const integer &operator %=( const integer &a )
408 {
409 return( operator =( *this - ( *this / a ) * a ) );
410 }
411
412 const integer &operator %=( difference_type n )
413 {
414 return( operator =( *this - ( *this / n ) * n ) );
415 }
416
417
418 const integer &operator &=( const integer &a )
419 {
420 for( size_type i = 0 ; i < DATA_NUM ; i++ )
421 {
422 data_[ i ] &= a.data_[ i ];
423 }
424 length_ = DATA_NUM;
425 for( difference_type j = DATA_NUM - 1 ; j >= 0 ; j-- )
426 {
427 if( data_[ length_ - 1 ] != 0 )
428 {
429 break;
430 }
431 length_--;
432 }
433 return( *this );
434 }
435
436 const integer &operator |=( const integer &a )
437 {
438 for( size_type i = 0 ; i < DATA_NUM ; i++ )
439 {
440 data_[ i ] |= a.data_[ i ];
441 }
442 length_ = length_ > a.length_ ? length_ : a.length_;
443 return( *this );
444 }
445
446 const integer &operator ^=( const integer &a )
447 {
448 for( size_type i = 0 ; i < DATA_NUM ; i++ )
449 {
450 data_[ i ] ^= a.data_[ i ];
451 }
452 length_ = DATA_NUM;
453 for( difference_type j = DATA_NUM - 1 ; j >= 0 ; j-- )
454 {
455 if( data_[ length_ - 1 ] != 0 )
456 {
457 break;
458 }
459 length_--;
460 }
461 return( *this );
462 }
463
464 integer &operator ++( ) // 前置型
465 {
466 *this += 1;
467 return( *this );
468 }
469
470 const integer operator ++( int ) // 後置型
471 {
472 integer old_val( *this );
473 *this += 1;
474 return( old_val );
475 }
476
477 integer &operator --( ) // 前置型
478 {
479 *this -= 1;
480 return( *this );
481 }
482
483 const integer operator --( int ) // 後置型
484 {
485 integer old_val( *this );
486 *this -= 1;
487 return( old_val );
488 }
489
490
491 bool operator ==( const integer &a ) const { return( sign_ == a.sign_ && acmp( *this, a ) == 0 ); }
492 bool operator !=( const integer &a ) const { return( !( *this == a ) ); }
493 bool operator < ( const integer &a ) const { return( !( *this >= a ) ); }
494 bool operator <=( const integer &a ) const { return( a >= *this ); }
495 bool operator > ( const integer &a ) const { return( a < *this ); }
496 bool operator >=( const integer &a ) const
497 {
498 if( sign_ && !a.sign_ )
499 {
500 return( true );
501 }
502 else if( !sign_ && a.sign_ )
503 {
504 return( false );
505 }
506 else
507 {
508 bool cmp = acmp( *this, a ) >= 0;
509 return( sign_ ? cmp : !cmp );
510 }
511 }
512
513 const ::std::string to_string( ) const
514 {
515 if( length_ == 0 )
516 {
517 return( "0" );
518 }
519 else if( length_ == 1 )
520 {
521 char tmp[ 20 ];
522 sprintf( tmp, "%d", data_[ 0 ] );
523 return( ( sign_ ? "" : "-" ) + ::std::string( tmp ) );
524 }
525 else
526 {
527 ::std::string s = "";
528 integer dmy( *this );
529 while( dmy.length_ != 0 )
530 {
531 difference_type t = 0;
532 for( difference_type i = dmy.length_ - 1 ; i >= 0 ; i-- )
533 {
534 t = t * BASE + dmy.data_[ i ];
535 dmy.data_[ i ] = static_cast< value_type >( t / 10 );
536 t %= 10;
537 }
538 if( dmy.data_[ dmy.length_ - 1 ] == 0 )
539 {
540 dmy.length_--;
541 }
542 s = static_cast< char >( '0' + t ) + s;
543 }
544 return( ( sign_ ? "" : "-" ) + s );
545 }
546 }
547
548 int to_int( ) const
549 {
550 if( length_ == 0 )
551 {
552 return( 0 );
553 }
554 else if( length_ > 4 )
555 {
556 // オーバーフロー
557 std::cerr << "overflow!!" << std::endl;
558 return( 0 );
559 }
560 else
561 {
562 return( ( sign_ ? 1 : -1 ) * ( data_[ 0 ] + BASE * ( data_[ 1 ] + BASE * ( data_[ 2 ] + BASE * data_[ 3 ] ) ) ) );
563 }
564 }
565
566 int to_uint( ) const
567 {
568 if( length_ == 0 )
569 {
570 return( 0 );
571 }
572 else if( length_ > 4 )
573 {
574 // オーバーフロー
575 std::cerr << "overflow!!" << std::endl;
576 return( 0 );
577 }
578 else
579 {
580 return( data_[ 0 ] + BASE * ( data_[ 1 ] + BASE * ( data_[ 2 ] + BASE * data_[ 3 ] ) ) );
581 }
582 }
583
584 protected:
585 static int acmp( const integer &a, const integer &b )
586 {
587 if( a.length_ > b.length_ )
588 {
589 return ( 1 );
590 }
591 else if( b.length_ > a.length_ )
592 {
593 return ( -1 );
594 }
595 else
596 {
597 for( difference_type i = a.length_ - 1 ; i >= 0 ; i-- )
598 {
599 if( a.data_[ i ] < b.data_[ i ] )
600 {
601 return( -1 );
602 }
603 else if( a.data_[ i ] > b.data_[ i ] )
604 {
605 return( 1 );
606 }
607 }
608 return( 0 );
609 }
610 }
611
612 static void aadd( integer &a0, const integer &b0 )
613 {
614 const integer *pa = a0.length_ >= b0.length_ ? &a0 : &b0;
615 const integer *pb = a0.length_ >= b0.length_ ? &b0 : &a0;
616
617 const integer &a = *pa;
618 const integer &b = *pb;
619
620 size_type i;
621 difference_type t = 0;
622
623 for( i = 0 ; i < b.length_ ; i++ )
624 {
625 t += a.data_[ i ] + b.data_[ i ];
626
627 if( t < BASE )
628 {
629 a0.data_[ i ] = static_cast< value_type >( t );
630 t = 0;
631 }
632 else
633 {
634 a0.data_[ i ] = static_cast< value_type >( t - BASE );
635 t = 1;
636 }
637 }
638
639 while( i < a.length_ && t != 0 )
640 {
641 t += a.data_[ i ];
642
643 if( t < BASE )
644 {
645 a0.data_[ i ] = static_cast< value_type >( t );
646 t = 0;
647 }
648 else
649 {
650 a0.data_[ i ] = static_cast< value_type >( t - BASE );
651 t = 1;
652 }
653
654 i++;
655 }
656
657 for( ; i < a.length_ ; i++ )
658 {
659 a0.data_[ i ] = a.data_[ i ];
660 }
661
662 if( t == 0 )
663 {
664 a0.length_ = a.length_;
665 }
666 else
667 {
668 if( a.length_ <= DATA_NUM )
669 {
670 a0.length_ = a.length_ + 1;
671 a0.data_[ i ] = 1;
672 }
673 else
674 {
675 std::cerr << "overflow!!" << std::endl;
676 }
677 }
678 }
679
680 static bool asub( integer &a0, const integer &b0 )
681 {
682 int c = acmp( a0, b0 );
683 if( c == 0 )
684 {
685 a0 = integer( );
686 return( true );
687 }
688
689 const integer *pa = c >= 0 ? &a0 : &b0;
690 const integer *pb = c >= 0 ? &b0 : &a0;
691
692 const integer &a = *pa;
693 const integer &b = *pb;
694
695 size_type i;
696 difference_type t = 0;
697
698 for( i = 0 ; i < b.length_ ; i++ )
699 {
700 t = a.data_[ i ] - b.data_[ i ] - t;
701
702 if( t >= 0 )
703 {
704 a0.data_[ i ] = static_cast< value_type >( t );
705 t = 0;
706 }
707 else
708 {
709 a0.data_[ i ] = static_cast< value_type >( t + BASE );
710 t = 1;
711 }
712 }
713
714 while( i < a.length_ && t != 0 )
715 {
716 t = a.data_[ i ] - t;
717
718 if( t >= 0 )
719 {
720 a0.data_[ i ] = static_cast< value_type >( t );
721 t = 0;
722 }
723 else
724 {
725 a0.data_[ i ] = static_cast< value_type >( t + BASE );
726 t = 1;
727 }
728
729 i++;
730 }
731
732 for( ; i < a.length_ ; i++ )
733 {
734 a0.data_[ i ] = a.data_[ i ];
735 }
736
737 a0.length_ = a.length_;
738
739 while( a0.data_[ a0.length_ - 1 ] == 0 )
740 {
741 a0.length_--;
742 }
743
744 return( c >= 0 );
745 }
746
747 static void shift_up( integer &a, difference_type n )
748 {
749 if( a.length_ == 0 || n == 0 )
750 {
751 }
752 else if( n < 0 )
753 {
754 shift_down( a, -n );
755 }
756 else
757 {
758 difference_type i;
759 for( i = a.length_ - 1 ; i >= 0 ; i-- )
760 {
761 a.data_[ i + n ] = a.data_[ i ];
762 }
763 for( i = n - 1 ; i >= 0 ; i-- )
764 {
765 a.data_[ i ] = 0;
766 }
767 a.length_ += n;
768 }
769 }
770
771 static void shift_down( integer &a, difference_type n )
772 {
773 difference_type len = a.length_;
774 if( a.length_ == 0 || n == 0 )
775 {
776 }
777 else if( n < 0 )
778 {
779 shift_up( a, -n );
780 }
781 else if( len <= n )
782 {
783 a = integer( 0 );
784 }
785 else
786 {
787 difference_type i;
788 for( i = 0 ; i < len - n ; i++ )
789 {
790 a.data_[ i ] = a.data_[ i + n ];
791 }
792 for( ; i < len ; i++ )
793 {
794 a.data_[ i ] = 0;
795 }
796 a.length_ -= n;
797 }
798 }
799
800 static integer read( const ::std::string &str )
801 {
802 if( str.size( ) == 0 )
803 {
804 return( integer( 0 ) );
805 }
806 else
807 {
808 size_type i, k = 0;
809 bool sign = true;
810 if( str[ 0 ] == '-' )
811 {
812 sign = false;
813 k++;
814 }
815 else if( str[ 0 ] == '+' )
816 {
817 k++;
818 }
819
820 if( str.size( ) - k < 10 )
821 {
822 return( integer( ::atoi( str.c_str( ) ) ) );
823 }
824
825 for( i = k ; i < str.size( ) ; i++ )
826 {
827 // 符号を除いた部分をコピーする．
828 if( '0' <= str[ i ] && str[ i ] <= '9' )
829 {
830 }
831 else
832 {
833 break;
834 }
835 }
836
837 ::std::string s = str.substr( k, i - k + 1 );
838
839 integer x( 0 );
840 integer base( 100000000 ), b( 1 );
841 while( !s.empty( ) )
842 {
843 difference_type len = s.size( );
844 if( len > 8 )
845 {
846 x += integer( ::atoi( ( s.substr( len - 8 ) ).c_str( ) ) ) * b;
847 b *= base;
848 s = s.substr( 0, len - 8 );
849 }
850 else
851 {
852 x += integer( ::atoi( s.c_str( ) ) ) * b;
853 s = "";
854 }
855 }
856 x.sign_ = sign;
857 return( x );
858 }
859 }
860 };
861
862
863 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator +( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) += v2 ); }
864 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator -( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) -= v2 ); }
865 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator *( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) *= v2 ); }
866 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator /( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) /= v2 ); }
867 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator %( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) %= v2 ); }
868 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator |( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) |= v2 ); }
869 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator &( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) &= v2 ); }
870 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator ^( const integer< __256_N__ > &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) ^= v2 ); }
871
872 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator *( const integer< __256_N__ > &v1, const typename integer< __256_N__ >::difference_type &v2 ){ return( integer< __256_N__ >( v1 ) *= v2 ); }
873 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator *( const typename integer< __256_N__ >::difference_type &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v2 ) *= v1 ); }
874 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator /( const integer< __256_N__ > &v1, const typename integer< __256_N__ >::difference_type &v2 ){ return( integer< __256_N__ >( v1 ) /= v2 ); }
875
876 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator +( const integer< __256_N__ > &v1, const typename integer< __256_N__ >::difference_type &v2 ){ return( integer< __256_N__ >( v1 ) += v2 ); }
877 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator +( const typename integer< __256_N__ >::difference_type &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v2 ) += v1 ); }
878 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator -( const integer< __256_N__ > &v1, const typename integer< __256_N__ >::difference_type &v2 ){ return( integer< __256_N__ >( v1 ) -= v2 ); }
879 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator -( const typename integer< __256_N__ >::difference_type &v1, const integer< __256_N__ > &v2 ){ return( integer< __256_N__ >( v1 ) -= v2 ); }
880
881 template < unsigned int __256_N__ > inline const integer< __256_N__ > operator %( const integer< __256_N__ > &v1, const typename integer< __256_N__ >::difference_type &v2 ){ return( integer< __256_N__ >( v1 ) %= v2 ); }
882
883
884 template < unsigned int __256_N__ >
885 inline std::ostream &operator <<( std::ostream &out, const integer< __256_N__ > &a )
886 {
887 out << a.to_string( );
888 return( out );
889 }
890
891
892 // mist名前空間の終わり
893 _MIST_END
894
895
896 #endif // __INCLUDE_MIST_INTEGER_H__
897
898