diff --git a/.gitattributes b/.gitattributes index bd29bf7..ce362ee 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ # Licensed under the MIT License. *.sh text eol=lf +include/** linguist-vendored diff --git a/.gitignore b/.gitignore index 54081e6..ea7e825 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ a.out *.exe +*.obj *.o .vscode/ key.txt diff --git a/Compile-Win64.ps1 b/Compile-Win64.ps1 new file mode 100644 index 0000000..f29b4aa --- /dev/null +++ b/Compile-Win64.ps1 @@ -0,0 +1,3 @@ +# Licensed under the MIT License. + +Make @args CC="clang" O=".obj" E=".exe" EXTRAS='-Wno-deprecated-declarations -Iinclude/mpir_x64-windows/include/' LM='' LGMP='-linclude/mpir_x64-windows/lib/mpir.lib' diff --git a/Makefile b/Makefile index 2bb84c9..bf0adc8 100644 --- a/Makefile +++ b/Makefile @@ -1,312 +1,320 @@ # Licensed under the MIT License. -CC = gcc -CFLAGS = -O3 -pedantic -std=c99 -Wall -Wextra +O = +E = .exe +CC = gcc +CFLAGS = -O3 -pedantic -std=c99 -Wall -Wextra $(EXTRAS) TWOS_COMPLEMENT = -fno-strict-overflow -fwrapv -SIEVE_O = boolean_set.o list.o sieve.o -STRING_COLLECTION_O = list.o string_builder.o string_collection.o -PERMUTATION_ITERATOR_O = comparer.o equality_comparer.o permutation_iterator.o +LM = -lm +LGMP = -lgmp + +SIEVE_O = boolean_set$(O) list$(O) sieve$(O) +STRING_COLLECTION_O = list$(O) string_builder$(O) string_collection$(O) +PERMUTATION_ITERATOR_O = comparer$(O) equality_comparer$(O) permutation_iterator$(O) all: \ - id0001.o id0002.o id0003.o id0004.o id0005.o id0006.o id0007.o id0008.o \ - id0009.o id0010.o id0011.o id0012.o id0013.o id0014.o id0015.o id0016.o \ - id0017.o id0018.o id0019.o id0020.o id0021.o id0022.o id0023.o id0024.o \ - id0025.o id0026.o id0027.o id0028.o id0029.o id0030.o id0031.o id0032.o \ - id0033.o id0034.o id0035.o id0036.o id0037.o id0038.o id0039.o id0040.o \ - id0041.o id0042.o id0043.o id0044.o id0045.o id0046.o id0047.o id0048.o \ - id0049.o id0050.o id0051.o id0052.o id0053.o id0054.o id0055.o id0056.o \ - id0057.o id0058.o id0059.o id0060.o id0061.o id0062.o id0063.o id0064.o \ - id0065.o id0066.o id0068.o id0069.o id0070.o id0071.o id0072.o \ - id0073.o id0074.o id0075.o id0076.o id0077.o id0078.o id0079.o id0080.o - -djb2_hash.o: lib/hashes/djb2_hash.c lib/hashes/djb2_hash.h + id0001$(E) id0002$(E) id0003$(E) id0004$(E) id0005$(E) id0006$(E) \ + id0007$(E) id0008$(E) id0009$(E) id0010$(E) id0011$(E) id0012$(E) \ + id0013$(E) id0014$(E) id0015$(E) id0016$(E) id0017$(E) id0018$(E) \ + id0019$(E) id0020$(E) id0021$(E) id0022$(E) id0023$(E) id0024$(E) \ + id0025$(E) id0026$(E) id0027$(E) id0028$(E) id0029$(E) id0030$(E) \ + id0031$(E) id0032$(E) id0033$(E) id0034$(E) id0035$(E) id0036$(E) \ + id0037$(E) id0038$(E) id0039$(E) id0040$(E) id0041$(E) id0042$(E) \ + id0043$(E) id0044$(E) id0045$(E) id0046$(E) id0047$(E) id0048$(E) \ + id0049$(E) id0050$(E) id0051$(E) id0052$(E) id0053$(E) id0054$(E) \ + id0055$(E) id0056$(E) id0057$(E) id0058$(E) id0059$(E) id0060$(E) \ + id0061$(E) id0062$(E) id0063$(E) id0064$(E) id0065$(E) id0066$(E) \ + id0068$(E) id0069$(E) id0070$(E) id0071$(E) id0072$(E) id0073$(E) \ + id0074$(E) #id0075$(E) id0076$(E) id0077$(E) id0078$(E) id0079$(E) + +djb2_hash$(O): lib/hashes/djb2_hash.c lib/hashes/djb2_hash.h $(CC) $(CFLAGS) -c $< -o $@ -pjw_hash.o: lib/hashes/pjw_hash.c lib/hashes/pjw_hash.h +pjw_hash$(O): lib/hashes/pjw_hash.c lib/hashes/pjw_hash.h $(CC) $(CFLAGS) -c $< -o $@ -sdbm_hash.o: lib/hashes/sdbm_hash.c lib/hashes/sdbm_hash.h +sdbm_hash$(O): lib/hashes/sdbm_hash.c lib/hashes/sdbm_hash.h $(CC) $(CFLAGS) -c $< -o $@ -divisor_primality_test.o: \ +divisor_primality_test$(O): \ lib/primality_tests/divisor_primality_test.c \ lib/primality_tests/divisor_primality_test.h $(CC) $(CFLAGS) -c $< -o $@ -miller_rabin_primality_test.o: \ +miller_rabin_primality_test$(O): \ lib/primality_tests/miller_rabin_primality_test.c \ lib/primality_tests/miller_rabin_primality_test.h $(CC) $(CFLAGS) -c $< -o $@ -boolean_set.o: lib/boolean_set.c lib/boolean_set.h +boolean_set$(O): lib/boolean_set.c lib/boolean_set.h $(CC) $(CFLAGS) -c $< -o $@ -comparer.o: lib/comparer.c lib/comparer.h +comparer$(O): lib/comparer.c lib/comparer.h $(CC) $(CFLAGS) -c $< -o $@ -euler.o: lib/euler.c lib/euler.h +euler$(O): lib/euler.c lib/euler.h $(CC) $(CFLAGS) -c $< -o $@ -equality_comparer.o: lib/equality_comparer.c lib/equality_comparer.h +equality_comparer$(O): lib/equality_comparer.c lib/equality_comparer.h $(CC) $(CFLAGS) -c $< -o $@ -factor_iterator.o: lib/factor_iterator.c lib/factor_iterator.h +factor_iterator$(O): lib/factor_iterator.c lib/factor_iterator.h $(CC) $(CFLAGS) -c $< -o $@ -list.o: lib/list.c lib/list.h +list$(O): lib/list.c lib/list.h $(CC) $(CFLAGS) -c $< -o $@ -math.o: lib/math.c lib/euler.h +math$(O): lib/math.c lib/euler.h $(CC) $(CFLAGS) -c $< -o $@ -permutation_iterator.o: lib/permutation_iterator.c lib/permutation_iterator.h +permutation_iterator$(O): lib/permutation_iterator.c lib/permutation_iterator.h $(CC) $(CFLAGS) -c $< -o $@ -sieve.o: lib/sieve.c lib/sieve.h +sieve$(O): lib/sieve.c lib/sieve.h $(CC) $(CFLAGS) -c $< -o $@ -series.o: lib/series.c lib/series.h +series$(O): lib/series.c lib/series.h $(CC) $(CFLAGS) -c $< -o $@ -string.o: lib/string.c lib/string.h +string$(O): lib/string.c lib/string.h $(CC) $(CFLAGS) -c $< -o $@ -string_builder.o: lib/string_builder.c lib/string_builder.h +string_builder$(O): lib/string_builder.c lib/string_builder.h $(CC) $(CFLAGS) -c $< -o $@ -string_collection.o: lib/string_collection.c lib/string_collection.h +string_collection$(O): lib/string_collection.c lib/string_collection.h $(CC) $(CFLAGS) -c $< -o $@ -totient.o: lib/totient.c lib/totient.h +totient$(O): lib/totient.c lib/totient.h $(CC) $(CFLAGS) -c $< -o $@ -id0001.o: src/id0001.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0001$(E): src/id0001.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0002.o: src/id0002.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0002$(E): src/id0002.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0003.o: src/id0003.c euler.o factor_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o factor_iterator.o $(SIEVE_O) -lm +id0003$(E): src/id0003.c euler$(O) factor_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) factor_iterator$(O) $(SIEVE_O) $(LM) -id0004.o: src/id0004.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0004$(E): src/id0004.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0005.o: src/id0005.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0005$(E): src/id0005.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0006.o: src/id0006.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0006$(E): src/id0006.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0007.o: src/id0007.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0007$(E): src/id0007.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0008.o: src/id0008.c euler.o series.o - $(CC) $(CFLAGS) $< -o $@ euler.o series.o +id0008$(E): src/id0008.c euler$(O) series$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) series$(O) -id0009.o: src/id0009.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o -lm +id0009$(E): src/id0009.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(LM) -id0010.o: src/id0010.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0010$(E): src/id0010.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0011.o: src/id0011.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0011$(E): src/id0011.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0012.o: src/id0012.c euler.o factor_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o factor_iterator.o $(SIEVE_O) -lm +id0012$(E): src/id0012.c euler$(O) factor_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) factor_iterator$(O) $(SIEVE_O) $(LM) -id0013.o: src/id0013.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0013$(E): src/id0013.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0014.o: src/id0014.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0014$(E): src/id0014.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0015.o: src/id0015.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0015$(E): src/id0015.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0016.o: src/id0016.c euler.o string.o series.o - $(CC) $(CFLAGS) $< -o $@ euler.o string.o series.o -lgmp +id0016$(E): src/id0016.c euler$(O) string$(O) series$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string$(O) series$(O) $(LGMP) -id0017.o: src/id0017.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0017$(E): src/id0017.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0018.o: src/id0018.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0018$(E): src/id0018.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0019.o: src/id0019.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0019$(E): src/id0019.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0020.o: src/id0020.c euler.o string.o series.o - $(CC) $(CFLAGS) $< -o $@ euler.o string.o series.o -lgmp +id0020$(E): src/id0020.c euler$(O) string$(O) series$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string$(O) series$(O) $(LGMP) -id0021.o: src/id0021.c euler.o factor_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o factor_iterator.o $(SIEVE_O) -lm +id0021$(E): src/id0021.c euler$(O) factor_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) factor_iterator$(O) $(SIEVE_O) $(LM) -id0022.o: src/id0022.c euler.o string.o $(STRING_COLLECTION_O) - $(CC) $(CFLAGS) $< -o $@ euler.o string.o $(STRING_COLLECTION_O) +id0022$(E): src/id0022.c euler$(O) string$(O) $(STRING_COLLECTION_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string$(O) $(STRING_COLLECTION_O) -id0023.o: src/id0023.c euler.o factor_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o factor_iterator.o $(SIEVE_O) -lm +id0023$(E): src/id0023.c euler$(O) factor_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) factor_iterator$(O) $(SIEVE_O) $(LM) -id0024.o: src/id0024.c euler.o $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(PERMUTATION_ITERATOR_O) +id0024$(E): src/id0024.c euler$(O) $(PERMUTATION_ITERATOR_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(PERMUTATION_ITERATOR_O) -id0025.o: src/id0025.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o -lgmp +id0025$(E): src/id0025.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(LGMP) -id0026.o: src/id0026.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0026$(E): src/id0026.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0027.o: src/id0027.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0027$(E): src/id0027.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0028.o: src/id0028.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0028$(E): src/id0028.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0029.o: src/id0029.c equality_comparer.o euler.o list.o - $(CC) $(CFLAGS) $< -o $@ equality_comparer.o euler.o list.o -lm +id0029$(E): src/id0029.c equality_comparer$(O) euler$(O) list$(O) + $(CC) $(CFLAGS) $< -o $@ equality_comparer$(O) euler$(O) list$(O) $(LM) -id0030.o: src/id0030.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o -lm +id0030$(E): src/id0030.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(LM) -id0031.o: src/id0031.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0031$(E): src/id0031.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0032.o: src/id0032.c euler.o list.o $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ euler.o list.o $(PERMUTATION_ITERATOR_O) +id0032$(E): src/id0032.c euler$(O) list$(O) $(PERMUTATION_ITERATOR_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) list$(O) $(PERMUTATION_ITERATOR_O) -id0033.o: src/id0033.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0033$(E): src/id0033.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0034.o: src/id0034.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0034$(E): src/id0034.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0035.o: src/id0035.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0035$(E): src/id0035.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0036.o: src/id0036.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0036$(E): src/id0036.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0037.o: src/id0037.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0037$(E): src/id0037.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0038.o: src/id0038.c comparer.o euler.o string_builder.o - $(CC) $(CFLAGS) $< -o $@ comparer.o euler.o string_builder.o +id0038$(E): src/id0038.c comparer$(O) euler$(O) string_builder$(O) + $(CC) $(CFLAGS) $< -o $@ comparer$(O) euler$(O) string_builder$(O) -id0039.o: src/id0039.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0039$(E): src/id0039.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) -id0040.o: src/id0040.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0040$(E): src/id0040.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0041.o: src/id0041.c miller_rabin_primality_test.o euler.o list.o \ +id0041$(E): src/id0041.c miller_rabin_primality_test$(O) euler$(O) list$(O) \ $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o list.o $(PERMUTATION_ITERATOR_O) -lm + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) list$(O) $(PERMUTATION_ITERATOR_O) $(LM) -id0042.o: src/id0042.c euler.o math.o $(STRING_COLLECTION_O) - $(CC) $(CFLAGS) $< -o $@ euler.o math.o $(STRING_COLLECTION_O) -lm +id0042$(E): src/id0042.c euler$(O) math$(O) $(STRING_COLLECTION_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(STRING_COLLECTION_O) $(LM) -id0043.o: src/id0043.c euler.o string_builder.o $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ euler.o string_builder.o $(PERMUTATION_ITERATOR_O) -lm +id0043$(E): src/id0043.c euler$(O) string_builder$(O) $(PERMUTATION_ITERATOR_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string_builder$(O) $(PERMUTATION_ITERATOR_O) $(LM) -id0044.o: src/id0044.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0044$(E): src/id0044.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) -id0045.o: src/id0045.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0045$(E): src/id0045.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) -id0046.o: src/id0046.c miller_rabin_primality_test.o euler.o - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o -lm +id0046$(E): src/id0046.c miller_rabin_primality_test$(O) euler$(O) + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) $(LM) -id0047.o: src/id0047.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0047$(E): src/id0047.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0048.o: src/id0048.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o -lgmp +id0048$(E): src/id0048.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(LGMP) -id0049.o: src/id0049.c equality_comparer.o euler.o string_builder.o \ - permutation_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ equality_comparer.o euler.o string_builder.o permutation_iterator.o $(SIEVE_O) -lm +id0049$(E): src/id0049.c equality_comparer$(O) euler$(O) string_builder$(O) \ + permutation_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ equality_comparer$(O) euler$(O) string_builder$(O) permutation_iterator$(O) $(SIEVE_O) $(LM) -id0050.o: src/id0050.c miller_rabin_primality_test.o euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o $(SIEVE_O) -lm +id0050$(E): src/id0050.c miller_rabin_primality_test$(O) euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) $(SIEVE_O) $(LM) -id0051.o: src/id0051.c miller_rabin_primality_test.o euler.o \ - string_builder.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o string_builder.o $(SIEVE_O) -lm +id0051$(E): src/id0051.c miller_rabin_primality_test$(O) euler$(O) \ + string_builder$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) string_builder$(O) $(SIEVE_O) $(LM) -id0052.o: src/id0052.c euler.o string_builder.o $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ euler.o string_builder.o $(PERMUTATION_ITERATOR_O) -lm +id0052$(E): src/id0052.c euler$(O) string_builder$(O) $(PERMUTATION_ITERATOR_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string_builder$(O) $(PERMUTATION_ITERATOR_O) $(LM) -id0053.o: src/id0053.c euler.o - $(CC) $(CFLAGS) $(TWOS_COMPLEMENT) $< -o $@ euler.o +id0053$(E): src/id0053.c euler$(O) + $(CC) $(CFLAGS) $(TWOS_COMPLEMENT) $< -o $@ euler$(O) -id0054.o: src/id0054.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0054$(E): src/id0054.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0055.o: src/id0055.c euler.o - $(CC) $(CFLAGS) $(TWOS_COMPLEMENT) $< -o $@ euler.o +id0055$(E): src/id0055.c euler$(O) + $(CC) $(CFLAGS) $(TWOS_COMPLEMENT) $< -o $@ euler$(O) -id0056.o: src/id0056.c euler.o string.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o string.o math.o -lgmp -lm +id0056$(E): src/id0056.c euler$(O) string$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string$(O) math$(O) $(LGMP) $(LM) -id0057.o: src/id0057.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o -lgmp +id0057$(E): src/id0057.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(LGMP) -id0058.o: src/id0058.c miller_rabin_primality_test.o euler.o - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o -lm +id0058$(E): src/id0058.c miller_rabin_primality_test$(O) euler$(O) + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) $(LM) -id0059.o: src/id0059.c euler.o string_builder.o - $(CC) $(CFLAGS) $< -o $@ euler.o string_builder.o +id0059$(E): src/id0059.c euler$(O) string_builder$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string_builder$(O) -id0060.o: src/id0060.c miller_rabin_primality_test.o euler.o math.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test.o euler.o math.o $(SIEVE_O) -lm +id0060$(E): src/id0060.c miller_rabin_primality_test$(O) euler$(O) math$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ miller_rabin_primality_test$(O) euler$(O) math$(O) $(SIEVE_O) $(LM) -id0061.o: src/id0061.c euler.o list.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o list.o math.o -lm +id0061$(E): src/id0061.c euler$(O) list$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) list$(O) math$(O) $(LM) -id0062.o: src/id0062.c sdbm_hash.o comparer.o euler.o list.o string_builder.o - $(CC) $(CFLAGS) $< -o $@ sdbm_hash.o comparer.o euler.o list.o string_builder.o +id0062$(E): src/id0062.c sdbm_hash$(O) comparer$(O) euler$(O) list$(O) string_builder$(O) + $(CC) $(CFLAGS) $< -o $@ sdbm_hash$(O) comparer$(O) euler$(O) list$(O) string_builder$(O) -id0063.o: src/id0063.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0063$(E): src/id0063.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) -id0064.o: src/id0064.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0064$(E): src/id0064.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) -id0065.o: src/id0065.c euler.o string.o - $(CC) $(CFLAGS) $< -o $@ euler.o string.o -lgmp +id0065$(E): src/id0065.c euler$(O) string$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) string$(O) $(LGMP) -id0066.o: src/id0066.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lgmp -lm +id0066$(E): src/id0066.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LGMP) $(LM) -id0068.o: src/id0068.c euler.o math.o $(PERMUTATION_ITERATOR_O) - $(CC) $(CFLAGS) $< -o $@ euler.o math.o $(PERMUTATION_ITERATOR_O) -lm +id0068$(E): src/id0068.c euler$(O) math$(O) $(PERMUTATION_ITERATOR_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(PERMUTATION_ITERATOR_O) $(LM) -id0069.o: src/id0069.c euler.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o $(SIEVE_O) -lm +id0069$(E): src/id0069.c euler$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) $(SIEVE_O) $(LM) -id0070.o: src/id0070.c euler.o equality_comparer.o string_builder.o \ - permutation_iterator.o $(SIEVE_O) - $(CC) $(CFLAGS) $< -o $@ euler.o equality_comparer.o string_builder.o permutation_iterator.o $(SIEVE_O) -lm +id0070$(E): src/id0070.c euler$(O) equality_comparer$(O) string_builder$(O) \ + permutation_iterator$(O) $(SIEVE_O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) equality_comparer$(O) string_builder$(O) permutation_iterator$(O) $(SIEVE_O) $(LM) -id0071.o: src/id0071.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0071$(E): src/id0071.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0072.o: src/id0072.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0072$(E): src/id0072.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0073.o: src/id0073.c euler.o - $(CC) $(CFLAGS) $< -o $@ euler.o +id0073$(E): src/id0073.c euler$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) -id0074.o: src/id0074.c equality_comparer.o euler.o list.o - $(CC) $(CFLAGS) $< -o $@ equality_comparer.o euler.o list.o +id0074$(E): src/id0074.c equality_comparer$(O) euler$(O) list$(O) + $(CC) $(CFLAGS) $< -o $@ equality_comparer$(O) euler$(O) list$(O) -id0075.o: src/id0075.c euler.o math.o - $(CC) $(CFLAGS) $< -o $@ euler.o math.o -lm +id0075$(E): src/id0075.c euler$(O) math$(O) + $(CC) $(CFLAGS) $< -o $@ euler$(O) math$(O) $(LM) clean: - rm -rf *.o + rm -rf *$(O) diff --git a/clean.bat b/clean.bat new file mode 100644 index 0000000..f65126d --- /dev/null +++ b/clean.bat @@ -0,0 +1,3 @@ +:: Licensed under the MIT License. + +rd *.exe diff --git a/euler b/euler new file mode 100644 index 0000000..5ec4827 Binary files /dev/null and b/euler differ diff --git a/include/mpir_x64-windows/include/gmp.h b/include/mpir_x64-windows/include/gmp.h new file mode 100644 index 0000000..a4ac54d --- /dev/null +++ b/include/mpir_x64-windows/include/gmp.h @@ -0,0 +1,1944 @@ +/* generated from gmp-h.in by gen_mpir_h.bat */ +/* Definitions for GNU multiple precision functions. -*- mode: c -*- +Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, +2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, +Inc. +Copyright 2008 William Hart, Gonzalo Tornaria +This file is part of the MPIR Library. +The MPIR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. +The MPIR Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ +#ifndef __GMP_H__ +#ifdef __SUNPRO_CC /* See: http://trac.sagemath.org/sage_trac/ticket/7849 */ +#include /* This is Bill Hart's fix, but I've applied it only */ +#include /* on Sun Studio */ +#endif +#if defined (__cplusplus) +#include /* for size_t */ +#include /* for std::istream, std::ostream, std::string */ +#include +#endif +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#ifdef _WIN32 +# ifdef _WIN64 +# define _LONG_LONG_LIMB 1 +# define GMP_LIMB_BITS 64 +# else +# define GMP_LIMB_BITS 32 +# endif +# define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS +# define SIZEOF_MP_LIMB_T (GMP_LIMB_BITS >> 3) +# define GMP_NAIL_BITS 0 +#endif +#endif +#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) +#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS) +#define GMP_NUMB_MAX GMP_NUMB_MASK +#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) +#ifndef __GNU_MP__ +#define __GNU_MP__ 4 +#define __need_size_t /* tell gcc stddef.h we only want size_t */ +#if ! defined (__cplusplus) +#include /* for size_t */ +#endif +#undef __need_size_t +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#endif +/* #if defined(__GMP_WITHIN_CONFIGURE) && defined(_WIN64) */ +#ifdef __WIN64 +#define _LONG_LONG_LIMB 1 +#endif +/* __STDC__ - some ANSI compilers define this only to 0, hence the use of + "defined" and not "__STDC__-0". In particular Sun workshop C 5.0 + sets __STDC__ to 0, but requires "##" for token pasting. + _AIX - gnu ansidecl.h asserts that all known AIX compilers are ANSI but + don't always define __STDC__. + __DECC - current versions of DEC C (5.9 for instance) for alpha are ANSI, + but don't define __STDC__ in their default mode. Don't know if old + versions might have been K&R, but let's not worry about that unless + someone is still using one. + _mips - gnu ansidecl.h says the RISC/OS MIPS compiler is ANSI in SVR4 + mode, but doesn't define __STDC__. + _MSC_VER - Microsoft C is ANSI, but __STDC__ is undefined unless the /Za + option is given (in which case it's 1). + _WIN32 - tested for by gnu ansidecl.h, no doubt on the assumption that + all w32 compilers are ansi. + Note: This same set of tests is used by gen-psqr.c and + demos/expr/expr-impl.h, so if anything needs adding, then be sure to + update those too. */ +#if defined (__STDC__) \ + || defined (__cplusplus) \ + || defined (_AIX) \ + || defined (__DECC) \ + || (defined (__mips) && defined (_SYSTYPE_SVR4)) \ + || defined (_MSC_VER) \ + || defined (_WIN32) +#define __GMP_HAVE_CONST 1 +#define __GMP_HAVE_PROTOTYPES 1 +#define __GMP_HAVE_TOKEN_PASTE 1 +#else +#define __GMP_HAVE_CONST 0 +#define __GMP_HAVE_PROTOTYPES 0 +#define __GMP_HAVE_TOKEN_PASTE 0 +#endif +#if __GMP_HAVE_CONST +#define __gmp_const const +#define __gmp_signed signed +#else +#define __gmp_const +#define __gmp_signed +#endif +/* __GMP_DECLSPEC supports Windows DLL versions of libmpir, and is empty in + all other circumstances. + When compiling objects for libmpir, __GMP_DECLSPEC is an export directive, + or when compiling for an application it's an import directive. The two + cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles + (and not defined from an application). + __GMP_DECLSPEC_XX is similarly used for libmpirxx. __GMP_WITHIN_GMPXX + indicates when building libmpirxx, and in that case libmpirxx functions are + exports, but libmpir functions which might get called are imports. + libmp.la uses __GMP_DECLSPEC, just as if it were libmpir.la. libmpir and + libmp don't call each other, so there's no conflict or confusion. + Libtool DLL_EXPORT define is not used. + There's no attempt to support GMP built both static and DLL. Doing so + would mean applications would have to tell us which of the two is going + to be used when linking, and that seems very tedious and error prone if + using GMP by hand, and equally tedious from a package since autoconf and + automake don't give much help. + __GMP_DECLSPEC is required on all documented global functions and + variables, the various internals in gmp-impl.h etc can be left unadorned. + But internals used by the test programs or speed measuring programs + should have __GMP_DECLSPEC, and certainly constants or variables must + have it or the wrong address will be resolved. + In gcc __declspec can go at either the start or end of a prototype. + In Microsoft C __declspec must go at the start, or after the type like + void __declspec(...) *foo()". There's no __dllexport or anything to + guard against someone foolish #defining dllexport. _export used to be + available, but no longer. + In Borland C _export still exists, but needs to go after the type, like + "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to + make use of that. Probably more trouble than it's worth. */ +#if defined (__GNUC__) +#define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__) +#define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__) +#endif +#if defined (_MSC_VER) || defined (__BORLANDC__) +#define __GMP_DECLSPEC_EXPORT __declspec(dllexport) +#define __GMP_DECLSPEC_IMPORT __declspec(dllimport) +#endif +#ifdef __WATCOMC__ +#define __GMP_DECLSPEC_EXPORT __export +#define __GMP_DECLSPEC_IMPORT __import +#endif +#ifdef __IBMC__ +#define __GMP_DECLSPEC_EXPORT _Export +#define __GMP_DECLSPEC_IMPORT _Import +#endif +#if defined( _MSC_VER ) +# if defined( MSC_BUILD_DLL ) +# define __GMP_LIBGMP_DLL 1 +# define __GMP_WITHIN_GMP 1 +# define __GMP_WITHIN_GMPXX 1 +# elif defined( MSC_USE_DLL ) +# define __GMP_LIBGMP_DLL 1 +# endif +#endif +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMP +/* compiling to go into a DLL libmpir */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into an application which will link to a DLL libmpir */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC +#endif +#ifdef __GMP_SHORT_LIMB +typedef unsigned int mp_limb_t; +typedef int mp_limb_signed_t; +#else +#ifdef _LONG_LONG_LIMB +typedef unsigned long long int mp_limb_t; +typedef long long int mp_limb_signed_t; +#else +typedef unsigned long int mp_limb_t; +typedef long int mp_limb_signed_t; +#endif +#endif +#ifdef _WIN64 +#define BITS_PER_UI BITS_PER_MP_LIMB +typedef mp_limb_t mpir_ui; +typedef mp_limb_signed_t mpir_si; +typedef mpir_ui mp_bitcnt_t; +#else +#define BITS_PER_UI BITS_PER_ULONG +typedef unsigned long mpir_ui; +typedef long mpir_si; +typedef mpir_ui mp_bitcnt_t; +#endif +#define GMP_UI_MAX ((mpir_ui)(~(mpir_ui)0)) +#define GMP_UI_HIBIT (GMP_UI_MAX ^ (GMP_UI_MAX >> 1)) +#define GMP_SI_MAX ((mpir_si)(GMP_UI_MAX ^ GMP_UI_HIBIT)) +#define GMP_SI_MIN ((mpir_si)GMP_UI_HIBIT) +#define __GMP_BITCNT_MAX (~(mp_bitcnt_t)0) +/* For reference, note that the name __mpz_struct gets into C++ mangled + function names, which means although the "__" suggests an internal, we + must leave this name for binary compatibility. */ +typedef struct +{ + int _mp_alloc; /* Number of *limbs* allocated and pointed + to by the _mp_d field. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpz_struct; +#endif /* __GNU_MP__ */ +typedef __mpz_struct mpz_t[1]; +typedef mp_limb_t * mp_ptr; +typedef __gmp_const mp_limb_t * mp_srcptr; +#if defined( _WIN64) +#define __GMP_MP_SIZE_T_INT 0 +typedef long long int mp_size_t; +typedef long int mp_exp_t; +#else +#define __GMP_MP_SIZE_T_INT 0 +typedef long int mp_size_t; +typedef long int mp_exp_t; +#endif +typedef struct +{ + __mpz_struct _mp_num; + __mpz_struct _mp_den; +} __mpq_struct; +typedef __mpq_struct mpq_t[1]; +typedef struct +{ + int _mp_prec; /* Max precision, in number of `mp_limb_t's. + Set by mpf_init and modified by + mpf_set_prec. The area pointed to by the + _mp_d field contains `prec' + 1 limbs. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpf_struct; +typedef __mpf_struct mpf_t[1]; +/* Available random number generation algorithms. */ +typedef enum +{ + GMP_RAND_ALG_DEFAULT = 0, + GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ +} gmp_randalg_t; +/* Random state struct. */ +typedef struct +{ + mpz_t _mp_seed; /* _mp_d member points to state of the generator. */ + gmp_randalg_t _mp_alg; /* Currently unused. */ + union { + void *_mp_lc; /* Pointer to function pointers structure. */ + } _mp_algdata; +} __gmp_randstate_struct; +typedef __gmp_randstate_struct gmp_randstate_t[1]; +/* Types for function declarations in gmp files. */ +/* ??? Should not pollute user name space with these ??? */ +typedef __gmp_const __mpz_struct *mpz_srcptr; +typedef __mpz_struct *mpz_ptr; +typedef __gmp_const __mpf_struct *mpf_srcptr; +typedef __mpf_struct *mpf_ptr; +typedef __gmp_const __mpq_struct *mpq_srcptr; +typedef __mpq_struct *mpq_ptr; +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMPXX +/* compiling to go into a DLL libmpirxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into a application which will link to a DLL libmpirxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC_XX +#endif +#if __GMP_HAVE_PROTOTYPES +#define __GMP_PROTO(x) x +#else +#define __GMP_PROTO(x) () +#endif +#ifndef __MPN +#if __GMP_HAVE_TOKEN_PASTE +#define __MPN(x) __gmpn_##x +#else +#define __MPN(x) __gmpn_/**/x +#endif +#endif +/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, + defines EOF but not FILE. */ +#if defined (FILE) \ + || defined (H_STDIO) \ + || defined (_H_STDIO) /* AIX */ \ + || defined (_STDIO_H) /* glibc, Sun, SCO */ \ + || defined (_STDIO_H_) /* BSD, OSF */ \ + || defined (__STDIO_H) /* Borland */ \ + || defined (__STDIO_H__) /* IRIX */ \ + || defined (_STDIO_INCLUDED) /* HPUX */ \ + || defined (_FILE_DEFINED) /* Microsoft */ \ + || defined (__STDIO__) /* Apple MPW MrC */ \ + || defined (_MSL_STDIO_H) /* Metrowerks */ \ + || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ + || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ +#define _GMP_H_HAVE_FILE 1 +#endif +/* In ISO C, if a prototype involving "struct obstack *" is given without + that structure defined, then the struct is scoped down to just the + prototype, causing a conflict if it's subsequently defined for real. So + only give prototypes if we've got obstack.h. */ +#if defined (_OBSTACK_H) /* glibc */ +#define _GMP_H_HAVE_OBSTACK 1 +#endif +/* The prototypes for gmp_vprintf etc are provided only if va_list is + available, via an application having included or . + Usually va_list is a typedef so can't be tested directly, but C99 + specifies that va_start is a macro (and it was normally a macro on past + systems too), so look for that. + will define some sort of va_list for vprintf and vfprintf, but + let's not bother trying to use that since it's not standard and since + application uses for gmp_vprintf etc will almost certainly require the + whole or anyway. */ +#ifdef va_start +#define _GMP_H_HAVE_VA_LIST 1 +#endif +/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */ +#if defined (__GNUC__) && defined (__GNUC_MINOR__) +#define __GMP_GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GMP_GNUC_PREREQ(maj, min) 0 +#endif +/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically + it means a function does nothing but examine its arguments and memory + (global or via arguments) to generate a return value, but changes nothing + and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets + tune/common.c etc turn this off when trying to write timing loops. */ +#if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE) +#define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +#define __GMP_ATTRIBUTE_PURE +#endif +/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean + to "g++ -Wold-style-cast". + Casts in "extern inline" code within an extern "C" block don't induce + these warnings, so __GMP_CAST only needs to be used on documented + macros. */ +#ifdef __cplusplus +#define __GMP_CAST(type, expr) (static_cast (expr)) +#else +#define __GMP_CAST(type, expr) ((type) (expr)) +#endif +/* An empty "throw ()" means the function doesn't throw any C++ exceptions, + this can save some stack frame info in applications. + Currently it's given only on functions which never divide-by-zero etc, + don't allocate memory, and are expected to never need to allocate memory. + This leaves open the possibility of a C++ throw from a future GMP + exceptions scheme. + mpz_set_ui etc are omitted to leave open the lazy allocation scheme + described in doc/tasks.html. mpz_get_d etc are omitted to leave open + exceptions for float overflows. + Note that __GMP_NOTHROW must be given on any inlines the same as on their + prototypes (for g++ at least, where they're used together). Note also + that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like + __GMP_ATTRIBUTE_PURE. */ +#if defined (__cplusplus) +#define __GMP_NOTHROW throw () +#else +#define __GMP_NOTHROW +#endif +/* PORTME: What other compilers have a useful "extern inline"? "static + inline" would be an acceptable substitute if the compiler (or linker) + discards unused statics. */ +/* gcc has __inline__ in all modes, including strict ansi. Give a prototype + for an inline too, so as to correctly specify "dllimport" on windows, in + case the function is called rather than inlined. */ +#ifdef __GNUC__ +#if defined(__APPLE_CC__) && (__APPLE_CC__ != 1) /* FSF GCC sets this flag to 1 on Apple machines */ +#if ! (__APPLE_CC__ >= 5465 && __STDC_VERSION__ >= 199901L) +#define __GMP_EXTERN_INLINE extern __inline__ +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#else /*GNU CC*/ +#if defined(__GNUC_STDC_INLINE__) || defined (__GNUC_GNU_INLINE__) +#define __GMP_EXTERN_INLINE extern __inline__ __attribute__((__gnu_inline__)) +#else +#define __GMP_EXTERN_INLINE extern __inline__ +#endif +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#endif +/* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1 + strict ANSI mode. Inlining is done even when not optimizing (ie. -O0 + mode, which is the default), but an unnecessary local copy of foo is + emitted unless -O is used. "extern __inline" is accepted, but the + "extern" appears to be ignored, ie. it becomes a plain global function + but which is inlined within its file. Don't know if all old versions of + DEC C supported __inline, but as a start let's do the right thing for + current versions. */ +#ifdef __DECC +#define __GMP_EXTERN_INLINE static __inline +#endif +/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict + ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes + place under -O. Without -O "foo" seems to be emitted whether it's used + or not, which is wasteful. "extern inline foo()" isn't useful, the + "extern" is apparently ignored, so foo is inlined if possible but also + emitted as a global, which causes multiple definition errors when + building a shared libmpir. */ +#ifdef __SCO_VERSION__ +#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE static inline +#endif +#endif +#if defined _MSC_VER +#define __GMP_EXTERN_INLINE static __inline +#endif +/* C++ always has "inline" and since it's a normal feature the linker should + discard duplicate non-inlined copies, or if it doesn't then that's a + problem for everyone, not just GMP. */ +#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE inline +#endif +/* Don't do any inlining within a configure run, since if the compiler ends + up emitting copies of the code into the object file it can end up + demanding the various support routines (like mpn_popcount) for linking, + making the "alloca" test and perhaps others fail. And on hppa ia64 a + pre-release gcc 3.2 was seen not respecting the "extern" in "extern + __inline__", triggering this problem too. */ +#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE +#undef __GMP_EXTERN_INLINE +#endif +/* By default, don't give a prototype when there's going to be an inline + version. Note in particular that Cray C++ objects to the combination of + prototype and inline. */ +#ifdef __GMP_EXTERN_INLINE +#ifndef __GMP_INLINE_PROTOTYPES +#define __GMP_INLINE_PROTOTYPES 0 +#endif +#else +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x)) +#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i)) +/* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted + to int by "~". */ +#define __GMP_UINT_MAX (~ (unsigned) 0) +#define __GMP_ULONG_MAX (~ (unsigned long) 0) +#define __GMP_USHRT_MAX ((unsigned short) ~0) +/* __builtin_expect is in gcc 3.0, and not in 2.95. */ +#if __GMP_GNUC_PREREQ (3,0) +#define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1) +#define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0) +#else +#define __GMP_LIKELY(cond) (cond) +#define __GMP_UNLIKELY(cond) (cond) +#endif +/* Allow direct user access to numerator and denominator of a mpq_t object. */ +#define mpq_numref(Q) (&((Q)->_mp_num)) +#define mpq_denref(Q) (&((Q)->_mp_den)) +#if defined (__cplusplus) +extern "C" { +using std::FILE; +#endif +#define mp_set_memory_functions __gmp_set_memory_functions +__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (size_t), + void *(*) (void *, size_t, size_t), + void (*) (void *, size_t))) __GMP_NOTHROW; +#define mp_get_memory_functions __gmp_get_memory_functions +__GMP_DECLSPEC void mp_get_memory_functions __GMP_PROTO ((void *(**) (size_t), + void *(**) (void *, size_t, size_t), + void (**) (void *, size_t))) __GMP_NOTHROW; +#define mp_bits_per_limb __gmp_bits_per_limb +__GMP_DECLSPEC extern __gmp_const int mp_bits_per_limb; +#define gmp_errno __gmp_errno +__GMP_DECLSPEC extern int gmp_errno; +#define gmp_version __gmp_version +__GMP_DECLSPEC extern __gmp_const char * __gmp_const gmp_version; +#define mpir_version __mpir_version +__GMP_DECLSPEC extern __gmp_const char * __gmp_const mpir_version; +/**************** Random number routines. ****************/ +#define gmp_randinit_default __gmp_randinit_default +__GMP_DECLSPEC void gmp_randinit_default __GMP_PROTO ((gmp_randstate_t)); +#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp +__GMP_DECLSPEC void gmp_randinit_lc_2exp __GMP_PROTO ((gmp_randstate_t, + mpz_srcptr, mpir_ui, + mp_bitcnt_t)); +#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size +__GMP_DECLSPEC int gmp_randinit_lc_2exp_size __GMP_PROTO ((gmp_randstate_t, mp_bitcnt_t)); +#define gmp_randinit_mt __gmp_randinit_mt +__GMP_DECLSPEC void gmp_randinit_mt __GMP_PROTO ((gmp_randstate_t)); +#define gmp_randinit_set __gmp_randinit_set +__GMP_DECLSPEC void gmp_randinit_set __GMP_PROTO ((gmp_randstate_t, __gmp_const __gmp_randstate_struct *)); +#define gmp_randseed __gmp_randseed +__GMP_DECLSPEC void gmp_randseed __GMP_PROTO ((gmp_randstate_t, mpz_srcptr)); +#define gmp_randseed_ui __gmp_randseed_ui +__GMP_DECLSPEC void gmp_randseed_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +#define gmp_randclear __gmp_randclear +__GMP_DECLSPEC void gmp_randclear __GMP_PROTO ((gmp_randstate_t)); +#define gmp_urandomb_ui __gmp_urandomb_ui +__GMP_DECLSPEC mpir_ui gmp_urandomb_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +#define gmp_urandomm_ui __gmp_urandomm_ui +__GMP_DECLSPEC mpir_ui gmp_urandomm_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +/**************** Formatted output routines. ****************/ +#define gmp_asprintf __gmp_asprintf +__GMP_DECLSPEC int gmp_asprintf __GMP_PROTO ((char **, __gmp_const char *, ...)); +#define gmp_fprintf __gmp_fprintf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif +#define gmp_obstack_printf __gmp_obstack_printf +#if defined (_GMP_H_HAVE_OBSTACK) +__GMP_DECLSPEC int gmp_obstack_printf __GMP_PROTO ((struct obstack *, __gmp_const char *, ...)); +#endif +#define gmp_obstack_vprintf __gmp_obstack_vprintf +#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, __gmp_const char *, va_list)); +#endif +#define gmp_printf __gmp_printf +__GMP_DECLSPEC int gmp_printf __GMP_PROTO ((__gmp_const char *, ...)); +#define gmp_snprintf __gmp_snprintf +__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, ...)); +#define gmp_sprintf __gmp_sprintf +__GMP_DECLSPEC int gmp_sprintf __GMP_PROTO ((char *, __gmp_const char *, ...)); +#define gmp_vasprintf __gmp_vasprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, __gmp_const char *, va_list)); +#endif +#define gmp_vfprintf __gmp_vfprintf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif +#define gmp_vprintf __gmp_vprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif +#define gmp_vsnprintf __gmp_vsnprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, va_list)); +#endif +#define gmp_vsprintf __gmp_vsprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, __gmp_const char *, va_list)); +#endif +/**************** Formatted input routines. ****************/ +#define gmp_fscanf __gmp_fscanf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif +#define gmp_scanf __gmp_scanf +__GMP_DECLSPEC int gmp_scanf __GMP_PROTO ((__gmp_const char *, ...)); +#define gmp_sscanf __gmp_sscanf +__GMP_DECLSPEC int gmp_sscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, ...)); +#define gmp_vfscanf __gmp_vfscanf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif +#define gmp_vscanf __gmp_vscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif +#define gmp_vsscanf __gmp_vsscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, va_list)); +#endif +/**************** Integer (i.e. Z) routines. ****************/ +#define _mpz_realloc __gmpz_realloc +#define mpz_realloc __gmpz_realloc +__GMP_DECLSPEC void *_mpz_realloc __GMP_PROTO ((mpz_ptr, mp_size_t)); +#define mpz_abs __gmpz_abs +#define __GMP_MPZ_ABS_MIN_ALLOC(x,y) (__GMP_ABS(y->_mp_size)) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs) +__GMP_DECLSPEC void mpz_abs __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif +#define __GMP_MPZ_ADD_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),__GMP_ABS(z->_mp_size))+1) +#define mpz_add __gmpz_add +__GMP_DECLSPEC void mpz_add __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define __GMP_MPZ_ADD_UI_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_add_ui __gmpz_add_ui +__GMP_DECLSPEC void mpz_add_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_addmul __gmpz_addmul +__GMP_DECLSPEC void mpz_addmul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_addmul_ui __gmpz_addmul_ui +__GMP_DECLSPEC void mpz_addmul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_and __gmpz_and +__GMP_DECLSPEC void mpz_and __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_array_init __gmpz_array_init +__GMP_DECLSPEC void mpz_array_init __GMP_PROTO ((mpz_ptr, mp_size_t, mp_size_t)); +#define mpz_bin_ui __gmpz_bin_ui +__GMP_DECLSPEC void mpz_bin_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_bin_uiui __gmpz_bin_uiui +__GMP_DECLSPEC void mpz_bin_uiui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_cdiv_q __gmpz_cdiv_q +__GMP_DECLSPEC void mpz_cdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp +__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_qr __gmpz_cdiv_qr +__GMP_DECLSPEC void mpz_cdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_r __gmpz_cdiv_r +__GMP_DECLSPEC void mpz_cdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp +__GMP_DECLSPEC void mpz_cdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_ui __gmpz_cdiv_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_clear __gmpz_clear +__GMP_DECLSPEC void mpz_clear __GMP_PROTO ((mpz_ptr)); +#define mpz_clears __gmpz_clears +__GMP_DECLSPEC void mpz_clears __GMP_PROTO ((mpz_ptr, ...)); +#define mpz_clrbit __gmpz_clrbit +__GMP_DECLSPEC void mpz_clrbit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_cmp __gmpz_cmp +__GMP_DECLSPEC int mpz_cmp __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmp_d __gmpz_cmp_d +__GMP_DECLSPEC int mpz_cmp_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define _mpz_cmp_si __gmpz_cmp_si +__GMP_DECLSPEC int _mpz_cmp_si __GMP_PROTO ((mpz_srcptr, mpir_si)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define _mpz_cmp_ui __gmpz_cmp_ui +__GMP_DECLSPEC int _mpz_cmp_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs __gmpz_cmpabs +__GMP_DECLSPEC int mpz_cmpabs __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs_d __gmpz_cmpabs_d +__GMP_DECLSPEC int mpz_cmpabs_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs_ui __gmpz_cmpabs_ui +__GMP_DECLSPEC int mpz_cmpabs_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_com __gmpz_com +__GMP_DECLSPEC void mpz_com __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_combit __gmpz_combit +__GMP_DECLSPEC void mpz_combit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_congruent_p __gmpz_congruent_p +__GMP_DECLSPEC int mpz_congruent_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p +__GMP_DECLSPEC int mpz_congruent_2exp_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_congruent_ui_p __gmpz_congruent_ui_p +__GMP_DECLSPEC int mpz_congruent_ui_p __GMP_PROTO ((mpz_srcptr, mpir_ui, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_divexact __gmpz_divexact +__GMP_DECLSPEC void mpz_divexact __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_divexact_ui __gmpz_divexact_ui +__GMP_DECLSPEC void mpz_divexact_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_divisible_p __gmpz_divisible_p +__GMP_DECLSPEC int mpz_divisible_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_divisible_ui_p __gmpz_divisible_ui_p +__GMP_DECLSPEC int mpz_divisible_ui_p __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p +__GMP_DECLSPEC int mpz_divisible_2exp_p __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_dump __gmpz_dump +__GMP_DECLSPEC void mpz_dump __GMP_PROTO ((mpz_srcptr)); +#define mpz_export __gmpz_export +__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, int, size_t, mpz_srcptr)); +#define mpz_fac_ui __gmpz_fac_ui +__GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_2fac_ui __gmpz_2fac_ui +__GMP_DECLSPEC void mpz_2fac_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_mfac_uiui __gmpz_mfac_uiui +__GMP_DECLSPEC void mpz_mfac_uiui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_primorial_ui __gmpz_primorial_ui +__GMP_DECLSPEC void mpz_primorial_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_fdiv_q __gmpz_fdiv_q +__GMP_DECLSPEC void mpz_fdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp +__GMP_DECLSPEC void mpz_fdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_qr __gmpz_fdiv_qr +__GMP_DECLSPEC void mpz_fdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_r __gmpz_fdiv_r +__GMP_DECLSPEC void mpz_fdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp +__GMP_DECLSPEC void mpz_fdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_ui __gmpz_fdiv_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_fib_ui __gmpz_fib_ui +__GMP_DECLSPEC void mpz_fib_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_fib2_ui __gmpz_fib2_ui +__GMP_DECLSPEC void mpz_fib2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpir_ui)); +#define mpz_fits_sint_p __gmpz_fits_sint_p +__GMP_DECLSPEC int mpz_fits_sint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_si_p __gmpz_fits_si_p +__GMP_DECLSPEC int mpz_fits_si_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_slong_p __gmpz_fits_slong_p +__GMP_DECLSPEC int mpz_fits_slong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_sshort_p __gmpz_fits_sshort_p +__GMP_DECLSPEC int mpz_fits_sshort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_uint_p __gmpz_fits_uint_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_DECLSPEC int mpz_fits_uint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ui_p __gmpz_fits_ui_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ui_p) +__GMP_DECLSPEC int mpz_fits_ui_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ulong_p __gmpz_fits_ulong_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_DECLSPEC int mpz_fits_ulong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ushort_p __gmpz_fits_ushort_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_DECLSPEC int mpz_fits_ushort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_gcd __gmpz_gcd +__GMP_DECLSPEC void mpz_gcd __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_gcd_ui __gmpz_gcd_ui +__GMP_DECLSPEC mpir_ui mpz_gcd_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_gcdext __gmpz_gcdext +__GMP_DECLSPEC void mpz_gcdext __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_get_d __gmpz_get_d +__GMP_DECLSPEC double mpz_get_d __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_get_d_2exp __gmpz_get_d_2exp +__GMP_DECLSPEC double mpz_get_d_2exp __GMP_PROTO ((signed long *, mpz_srcptr)); +#define mpz_get_si __gmpz_get_si +__GMP_DECLSPEC /* signed */ mpir_si mpz_get_si __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_get_str __gmpz_get_str +__GMP_DECLSPEC char *mpz_get_str __GMP_PROTO ((char *, int, mpz_srcptr)); +#define mpz_get_ui __gmpz_get_ui +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui) +__GMP_DECLSPEC mpir_ui mpz_get_ui __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_getlimbn __gmpz_getlimbn +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn) +__GMP_DECLSPEC mp_limb_t mpz_getlimbn __GMP_PROTO ((mpz_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_hamdist __gmpz_hamdist +__GMP_DECLSPEC mp_bitcnt_t mpz_hamdist __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_import __gmpz_import +__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, size_t, int, size_t, int, size_t, __gmp_const void *)); +#define mpz_init __gmpz_init +__GMP_DECLSPEC void mpz_init __GMP_PROTO ((mpz_ptr)); +#define mpz_init2 __gmpz_init2 +__GMP_DECLSPEC void mpz_init2 __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_inits __gmpz_inits +__GMP_DECLSPEC void mpz_inits __GMP_PROTO ((mpz_ptr, ...)); +#define mpz_init_set __gmpz_init_set +__GMP_DECLSPEC void mpz_init_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_init_set_d __gmpz_init_set_d +__GMP_DECLSPEC void mpz_init_set_d __GMP_PROTO ((mpz_ptr, double)); +#define mpz_init_set_si __gmpz_init_set_si +__GMP_DECLSPEC void mpz_init_set_si __GMP_PROTO ((mpz_ptr, mpir_si)); +#define mpz_init_set_str __gmpz_init_set_str +__GMP_DECLSPEC int mpz_init_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); +#define mpz_init_set_ui __gmpz_init_set_ui +__GMP_DECLSPEC void mpz_init_set_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_inp_raw __gmpz_inp_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, FILE *)); +#endif +#define mpz_inp_str __gmpz_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, FILE *, int)); +#endif +#define mpz_invert __gmpz_invert +__GMP_DECLSPEC int mpz_invert __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_ior __gmpz_ior +__GMP_DECLSPEC void mpz_ior __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_jacobi __gmpz_jacobi +__GMP_DECLSPEC int mpz_jacobi __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_kronecker mpz_jacobi /* alias */ +#define mpz_kronecker_si __gmpz_kronecker_si +__GMP_DECLSPEC int mpz_kronecker_si __GMP_PROTO ((mpz_srcptr, mpir_si)) __GMP_ATTRIBUTE_PURE; +#define mpz_kronecker_ui __gmpz_kronecker_ui +__GMP_DECLSPEC int mpz_kronecker_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_si_kronecker __gmpz_si_kronecker +__GMP_DECLSPEC int mpz_si_kronecker __GMP_PROTO ((mpir_si, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_ui_kronecker __gmpz_ui_kronecker +__GMP_DECLSPEC int mpz_ui_kronecker __GMP_PROTO ((mpir_ui, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_lcm __gmpz_lcm +__GMP_DECLSPEC void mpz_lcm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_lcm_ui __gmpz_lcm_ui +__GMP_DECLSPEC void mpz_lcm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_legendre mpz_jacobi /* alias */ +#define mpz_lucnum_ui __gmpz_lucnum_ui +__GMP_DECLSPEC void mpz_lucnum_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_lucnum2_ui __gmpz_lucnum2_ui +__GMP_DECLSPEC void mpz_lucnum2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpir_ui)); +#define mpz_millerrabin __gmpz_millerrabin +__GMP_DECLSPEC int mpz_millerrabin __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; +#define mpz_miller_rabin __gmpz_miller_rabin +__GMP_DECLSPEC int mpz_miller_rabin __GMP_PROTO ((mpz_srcptr, int, gmp_randstate_t)) __GMP_ATTRIBUTE_PURE; +#define mpz_mod __gmpz_mod +__GMP_DECLSPEC void mpz_mod __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */ +#define __GMP_MPZ_MUL_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+__GMP_ABS(z->_mp_size)+1) +#define mpz_mul __gmpz_mul +__GMP_DECLSPEC void mpz_mul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_mul_2exp __gmpz_mul_2exp +__GMP_DECLSPEC void mpz_mul_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define __GMP_MPZ_MUL_SI_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS+1) +#define mpz_mul_si __gmpz_mul_si +__GMP_DECLSPEC void mpz_mul_si __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_si)); +#define __GMP_MPZ_MUL_UI_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS+1) +#define mpz_mul_ui __gmpz_mul_ui +__GMP_DECLSPEC void mpz_mul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_neg __gmpz_neg +#define __GMP_MPZ_NEG_MIN_ALLOC(x,y) (__GMP_ABS(y->_mp_size)) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg) +__GMP_DECLSPEC void mpz_neg __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif +#define mpz_nextprime __gmpz_nextprime +__GMP_DECLSPEC void mpz_nextprime __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_next_prime_candidate __gmpz_next_prime_candidate +__GMP_DECLSPEC void mpz_next_prime_candidate __GMP_PROTO ((mpz_ptr, mpz_srcptr, gmp_randstate_t)); +#define mpz_out_raw __gmpz_out_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_raw __GMP_PROTO ((FILE *, mpz_srcptr)); +#endif +#define mpz_out_str __gmpz_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_str __GMP_PROTO ((FILE *, int, mpz_srcptr)); +#endif +#define mpz_perfect_power_p __gmpz_perfect_power_p +__GMP_DECLSPEC int mpz_perfect_power_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_perfect_square_p __gmpz_perfect_square_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_DECLSPEC int mpz_perfect_square_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_popcount __gmpz_popcount +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount) +__GMP_DECLSPEC mp_bitcnt_t mpz_popcount __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_pow_ui __gmpz_pow_ui +__GMP_DECLSPEC void mpz_pow_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_powm __gmpz_powm +__GMP_DECLSPEC void mpz_powm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr)); +#define mpz_powm_ui __gmpz_powm_ui +__GMP_DECLSPEC void mpz_powm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui, mpz_srcptr)); +#define mpz_probab_prime_p __gmpz_probab_prime_p +__GMP_DECLSPEC int mpz_probab_prime_p __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; +#define mpz_probable_prime_p __gmpz_probable_prime_p +__GMP_DECLSPEC int mpz_probable_prime_p __GMP_PROTO ((mpz_srcptr,gmp_randstate_t, int, mpir_ui)); +#define mpz_likely_prime_p __gmpz_likely_prime_p +__GMP_DECLSPEC int mpz_likely_prime_p __GMP_PROTO ((mpz_srcptr,gmp_randstate_t, mpir_ui)); +#define mpz_realloc2 __gmpz_realloc2 +__GMP_DECLSPEC void mpz_realloc2 __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_remove __gmpz_remove +__GMP_DECLSPEC mp_bitcnt_t mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_root __gmpz_root +__GMP_DECLSPEC int mpz_root __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_nthroot __gmpz_nthroot +__GMP_DECLSPEC void mpz_nthroot __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_rootrem __gmpz_rootrem +__GMP_DECLSPEC void mpz_rootrem __GMP_PROTO ((mpz_ptr,mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_rrandomb __gmpz_rrandomb +__GMP_DECLSPEC void mpz_rrandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mp_bitcnt_t)); +#define mpz_scan0 __gmpz_scan0 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan0 __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_scan1 __gmpz_scan1 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan1 __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define __GMP_MPZ_SET_MIN_ALLOC(x,y) __GMP_ABS(y->_mp_size) +#define mpz_set __gmpz_set +__GMP_DECLSPEC void mpz_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_set_d __gmpz_set_d +__GMP_DECLSPEC void mpz_set_d __GMP_PROTO ((mpz_ptr, double)); +#define mpz_set_f __gmpz_set_f +__GMP_DECLSPEC void mpz_set_f __GMP_PROTO ((mpz_ptr, mpf_srcptr)); +#define mpz_set_q __gmpz_set_q +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q) +__GMP_DECLSPEC void mpz_set_q __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#endif +#define __GMP_MPZ_SET_SI_MIN_ALLOC(x,y) (1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS) +#define mpz_set_si __gmpz_set_si +__GMP_DECLSPEC void mpz_set_si __GMP_PROTO ((mpz_ptr, mpir_si)); +#define mpz_set_str __gmpz_set_str +__GMP_DECLSPEC int mpz_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); +#define __GMP_MPZ_SET_UI_MIN_ALLOC(x,y) (1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS) +#define mpz_set_ui __gmpz_set_ui +__GMP_DECLSPEC void mpz_set_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_setbit __gmpz_setbit +__GMP_DECLSPEC void mpz_setbit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_size __gmpz_size +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size) +__GMP_DECLSPEC size_t mpz_size __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_sizeinbase __gmpz_sizeinbase +__GMP_DECLSPEC size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_sqrt __gmpz_sqrt +__GMP_DECLSPEC void mpz_sqrt __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_sqrtrem __gmpz_sqrtrem +__GMP_DECLSPEC void mpz_sqrtrem __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr)); +#define __GMP_MPZ_SUB_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),__GMP_ABS(z->_mp_size))+1) +#define mpz_sub __gmpz_sub +__GMP_DECLSPEC void mpz_sub __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define __GMP_MPZ_SUB_UI_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_sub_ui __gmpz_sub_ui +__GMP_DECLSPEC void mpz_sub_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define __GMP_MPZ_UI_SUB_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(z->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_ui_sub __gmpz_ui_sub +__GMP_DECLSPEC void mpz_ui_sub __GMP_PROTO ((mpz_ptr, mpir_ui, mpz_srcptr)); +#define mpz_submul __gmpz_submul +__GMP_DECLSPEC void mpz_submul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_submul_ui __gmpz_submul_ui +__GMP_DECLSPEC void mpz_submul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_swap __gmpz_swap +__GMP_DECLSPEC void mpz_swap __GMP_PROTO ((mpz_ptr, mpz_ptr)) __GMP_NOTHROW; +#define mpz_tdiv_ui __gmpz_tdiv_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_tdiv_q __gmpz_tdiv_q +__GMP_DECLSPEC void mpz_tdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp +__GMP_DECLSPEC void mpz_tdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tdiv_qr __gmpz_tdiv_qr +__GMP_DECLSPEC void mpz_tdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tdiv_r __gmpz_tdiv_r +__GMP_DECLSPEC void mpz_tdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp +__GMP_DECLSPEC void mpz_tdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tstbit __gmpz_tstbit +__GMP_DECLSPEC int mpz_tstbit __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_ui_pow_ui __gmpz_ui_pow_ui +__GMP_DECLSPEC void mpz_ui_pow_ui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_urandomb __gmpz_urandomb +__GMP_DECLSPEC void mpz_urandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mp_bitcnt_t)); +#define mpz_urandomm __gmpz_urandomm +__GMP_DECLSPEC void mpz_urandomm __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mpz_srcptr)); +#define mpz_xor __gmpz_xor +#define mpz_eor __gmpz_xor +__GMP_DECLSPEC void mpz_xor __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_limbs_read __gmpz_limbs_read +__GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr); +#define mpz_limbs_write __gmpz_limbs_write +__GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t); +#define mpz_limbs_modify __gmpz_limbs_modify +__GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t); +#define mpz_limbs_finish __gmpz_limbs_finish +__GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t); +#define mpz_roinit_n __gmpz_roinit_n +__GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t); +#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} +/****** Integer (i.e. Z) routines for intmaax_t/uintmax_t types ******/ +/* if stdint.h is available -- n.b: we do NOT include stdint.h ourselves */ +#if defined(INTMAX_MAX) +#define __GMP_BITS_PER_UINTMAX (8*sizeof(uintmax_t)) +#define mpz_get_ux __gmpz_get_ux +__GMP_DECLSPEC uintmax_t mpz_get_ux __GMP_PROTO ((mpz_srcptr)); +#define mpz_get_sx __gmpz_get_sx +__GMP_DECLSPEC intmax_t mpz_get_sx __GMP_PROTO ((mpz_srcptr)); +#define mpz_set_ux __gmpz_set_ux +__GMP_DECLSPEC void mpz_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t)); +#define mpz_set_sx __gmpz_set_sx +__GMP_DECLSPEC void mpz_set_sx __GMP_PROTO ((mpz_ptr, intmax_t)); +#define mpz_init_set_ux __gmpz_init_set_ux +__GMP_DECLSPEC void mpz_init_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t)); +#define mpz_init_set_sx __gmpz_init_set_sx +__GMP_DECLSPEC void mpz_init_set_sx __GMP_PROTO ((mpz_ptr, intmax_t)); +#endif +/**************** Rational (i.e. Q) routines. ****************/ +#define mpq_abs __gmpq_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs) +__GMP_DECLSPEC void mpq_abs __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif +#define mpq_add __gmpq_add +__GMP_DECLSPEC void mpq_add __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_canonicalize __gmpq_canonicalize +__GMP_DECLSPEC void mpq_canonicalize __GMP_PROTO ((mpq_ptr)); +#define mpq_clear __gmpq_clear +__GMP_DECLSPEC void mpq_clear __GMP_PROTO ((mpq_ptr)); +#define mpq_clears __gmpq_clears +__GMP_DECLSPEC void mpq_clears __GMP_PROTO ((mpq_ptr, ...)); +#define mpq_cmp __gmpq_cmp +__GMP_DECLSPEC int mpq_cmp __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_ATTRIBUTE_PURE; +#define _mpq_cmp_si __gmpq_cmp_si +__GMP_DECLSPEC int _mpq_cmp_si __GMP_PROTO ((mpq_srcptr, mpir_si, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define _mpq_cmp_ui __gmpq_cmp_ui +__GMP_DECLSPEC int _mpq_cmp_ui __GMP_PROTO ((mpq_srcptr, mpir_ui, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpq_cmp_z __gmpq_cmp_z +__GMP_DECLSPEC int mpq_cmp_z (mpq_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; +#define mpq_div __gmpq_div +__GMP_DECLSPEC void mpq_div __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_div_2exp __gmpq_div_2exp +__GMP_DECLSPEC void mpq_div_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, mp_bitcnt_t)); +#define mpq_equal __gmpq_equal +__GMP_DECLSPEC int mpq_equal __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpq_get_num __gmpq_get_num +__GMP_DECLSPEC void mpq_get_num __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#define mpq_get_den __gmpq_get_den +__GMP_DECLSPEC void mpq_get_den __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#define mpq_get_d __gmpq_get_d +__GMP_DECLSPEC double mpq_get_d __GMP_PROTO ((mpq_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpq_get_str __gmpq_get_str +__GMP_DECLSPEC char *mpq_get_str __GMP_PROTO ((char *, int, mpq_srcptr)); +#define mpq_init __gmpq_init +__GMP_DECLSPEC void mpq_init __GMP_PROTO ((mpq_ptr)); +#define mpq_inits __gmpq_inits +__GMP_DECLSPEC void mpq_inits __GMP_PROTO ((mpq_ptr, ...)); +#define mpq_inp_str __gmpq_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, FILE *, int)); +#endif +#define mpq_inv __gmpq_inv +__GMP_DECLSPEC void mpq_inv __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#define mpq_mul __gmpq_mul +__GMP_DECLSPEC void mpq_mul __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_mul_2exp __gmpq_mul_2exp +__GMP_DECLSPEC void mpq_mul_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, mp_bitcnt_t)); +#define mpq_neg __gmpq_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg) +__GMP_DECLSPEC void mpq_neg __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif +#define mpq_out_str __gmpq_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_out_str __GMP_PROTO ((FILE *, int, mpq_srcptr)); +#endif +#define mpq_set __gmpq_set +__GMP_DECLSPEC void mpq_set __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#define mpq_set_d __gmpq_set_d +__GMP_DECLSPEC void mpq_set_d __GMP_PROTO ((mpq_ptr, double)); +#define mpq_set_den __gmpq_set_den +__GMP_DECLSPEC void mpq_set_den __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_set_f __gmpq_set_f +__GMP_DECLSPEC void mpq_set_f __GMP_PROTO ((mpq_ptr, mpf_srcptr)); +#define mpq_set_num __gmpq_set_num +__GMP_DECLSPEC void mpq_set_num __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_set_si __gmpq_set_si +__GMP_DECLSPEC void mpq_set_si __GMP_PROTO ((mpq_ptr, mpir_si, mpir_ui)); +#define mpq_set_str __gmpq_set_str +__GMP_DECLSPEC int mpq_set_str __GMP_PROTO ((mpq_ptr, __gmp_const char *, int)); +#define mpq_set_ui __gmpq_set_ui +__GMP_DECLSPEC void mpq_set_ui __GMP_PROTO ((mpq_ptr, mpir_ui, mpir_ui)); +#define mpq_set_z __gmpq_set_z +__GMP_DECLSPEC void mpq_set_z __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_sub __gmpq_sub +__GMP_DECLSPEC void mpq_sub __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_swap __gmpq_swap +__GMP_DECLSPEC void mpq_swap __GMP_PROTO ((mpq_ptr, mpq_ptr)) __GMP_NOTHROW; +/**************** Float (i.e. F) routines. ****************/ +#define mpf_abs __gmpf_abs +__GMP_DECLSPEC void mpf_abs __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_add __gmpf_add +__GMP_DECLSPEC void mpf_add __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_add_ui __gmpf_add_ui +__GMP_DECLSPEC void mpf_add_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_ceil __gmpf_ceil +__GMP_DECLSPEC void mpf_ceil __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_clear __gmpf_clear +__GMP_DECLSPEC void mpf_clear __GMP_PROTO ((mpf_ptr)); +#define mpf_clears __gmpf_clears +__GMP_DECLSPEC void mpf_clears __GMP_PROTO ((mpf_ptr, ...)); +#define mpf_cmp __gmpf_cmp +__GMP_DECLSPEC int mpf_cmp __GMP_PROTO ((mpf_srcptr, mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_d __gmpf_cmp_d +__GMP_DECLSPEC int mpf_cmp_d __GMP_PROTO ((mpf_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_si __gmpf_cmp_si +__GMP_DECLSPEC int mpf_cmp_si __GMP_PROTO ((mpf_srcptr, mpir_si)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_ui __gmpf_cmp_ui +__GMP_DECLSPEC int mpf_cmp_ui __GMP_PROTO ((mpf_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_div __gmpf_div +__GMP_DECLSPEC void mpf_div __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_div_2exp __gmpf_div_2exp +__GMP_DECLSPEC void mpf_div_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, mp_bitcnt_t)); +#define mpf_div_ui __gmpf_div_ui +__GMP_DECLSPEC void mpf_div_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_dump __gmpf_dump +__GMP_DECLSPEC void mpf_dump __GMP_PROTO ((mpf_srcptr)); +#define mpf_eq __gmpf_eq +__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpf_fits_sint_p __gmpf_fits_sint_p +__GMP_DECLSPEC int mpf_fits_sint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_si_p __gmpf_fits_si_p +__GMP_DECLSPEC int mpf_fits_si_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_slong_p __gmpf_fits_slong_p +__GMP_DECLSPEC int mpf_fits_slong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_sshort_p __gmpf_fits_sshort_p +__GMP_DECLSPEC int mpf_fits_sshort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_uint_p __gmpf_fits_uint_p +__GMP_DECLSPEC int mpf_fits_uint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ui_p __gmpf_fits_ui_p +__GMP_DECLSPEC int mpf_fits_ui_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ulong_p __gmpf_fits_ulong_p +__GMP_DECLSPEC int mpf_fits_ulong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ushort_p __gmpf_fits_ushort_p +__GMP_DECLSPEC int mpf_fits_ushort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_floor __gmpf_floor +__GMP_DECLSPEC void mpf_floor __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_get_d __gmpf_get_d +__GMP_DECLSPEC double mpf_get_d __GMP_PROTO ((mpf_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpf_get_d_2exp __gmpf_get_d_2exp +__GMP_DECLSPEC double mpf_get_d_2exp __GMP_PROTO ((signed long *, mpf_srcptr)); +#define mpf_get_default_prec __gmpf_get_default_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_default_prec __GMP_PROTO ((void)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_prec __gmpf_get_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_prec __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_si __gmpf_get_si +__GMP_DECLSPEC mpir_si mpf_get_si __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_str __gmpf_get_str +__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr)); +#define mpf_get_ui __gmpf_get_ui +__GMP_DECLSPEC mpir_ui mpf_get_ui __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_init __gmpf_init +__GMP_DECLSPEC void mpf_init __GMP_PROTO ((mpf_ptr)); +#define mpf_init2 __gmpf_init2 +__GMP_DECLSPEC void mpf_init2 __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)); +#define mpf_inits __gmpf_inits +__GMP_DECLSPEC void mpf_inits __GMP_PROTO ((mpf_ptr, ...)); +#define mpf_init_set __gmpf_init_set +__GMP_DECLSPEC void mpf_init_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_init_set_d __gmpf_init_set_d +__GMP_DECLSPEC void mpf_init_set_d __GMP_PROTO ((mpf_ptr, double)); +#define mpf_init_set_si __gmpf_init_set_si +__GMP_DECLSPEC void mpf_init_set_si __GMP_PROTO ((mpf_ptr, mpir_si)); +#define mpf_init_set_str __gmpf_init_set_str +__GMP_DECLSPEC int mpf_init_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); +#define mpf_init_set_ui __gmpf_init_set_ui +__GMP_DECLSPEC void mpf_init_set_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_inp_str __gmpf_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, FILE *, int)); +#endif +#define mpf_integer_p __gmpf_integer_p +__GMP_DECLSPEC int mpf_integer_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_mul __gmpf_mul +__GMP_DECLSPEC void mpf_mul __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_mul_2exp __gmpf_mul_2exp +__GMP_DECLSPEC void mpf_mul_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, mp_bitcnt_t)); +#define mpf_mul_ui __gmpf_mul_ui +__GMP_DECLSPEC void mpf_mul_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_neg __gmpf_neg +__GMP_DECLSPEC void mpf_neg __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_out_str __gmpf_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_out_str __GMP_PROTO ((FILE *, int, size_t, mpf_srcptr)); +#endif +#define mpf_pow_ui __gmpf_pow_ui +__GMP_DECLSPEC void mpf_pow_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_random2 __gmpf_random2 +__GMP_DECLSPEC void mpf_random2 __GMP_PROTO ((mpf_ptr, mp_size_t, mp_exp_t)); +#define mpf_rrandomb __gmpf_rrandomb +__GMP_DECLSPEC void mpf_rrandomb __GMP_PROTO ((mpf_ptr, gmp_randstate_t, mp_size_t, mp_exp_t)); +#define mpf_reldiff __gmpf_reldiff +__GMP_DECLSPEC void mpf_reldiff __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_set __gmpf_set +__GMP_DECLSPEC void mpf_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_set_d __gmpf_set_d +__GMP_DECLSPEC void mpf_set_d __GMP_PROTO ((mpf_ptr, double)); +#define mpf_set_default_prec __gmpf_set_default_prec +__GMP_DECLSPEC void mpf_set_default_prec __GMP_PROTO ((mp_bitcnt_t)) __GMP_NOTHROW; +#define mpf_set_prec __gmpf_set_prec +__GMP_DECLSPEC void mpf_set_prec __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)); +#define mpf_set_prec_raw __gmpf_set_prec_raw +__GMP_DECLSPEC void mpf_set_prec_raw __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)) __GMP_NOTHROW; +#define mpf_set_q __gmpf_set_q +__GMP_DECLSPEC void mpf_set_q __GMP_PROTO ((mpf_ptr, mpq_srcptr)); +#define mpf_set_si __gmpf_set_si +__GMP_DECLSPEC void mpf_set_si __GMP_PROTO ((mpf_ptr, mpir_si)); +#define mpf_set_str __gmpf_set_str +__GMP_DECLSPEC int mpf_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); +#define mpf_set_ui __gmpf_set_ui +__GMP_DECLSPEC void mpf_set_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_set_z __gmpf_set_z +__GMP_DECLSPEC void mpf_set_z __GMP_PROTO ((mpf_ptr, mpz_srcptr)); +#define mpf_size __gmpf_size +__GMP_DECLSPEC size_t mpf_size __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_sqrt __gmpf_sqrt +__GMP_DECLSPEC void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_sqrt_ui __gmpf_sqrt_ui +__GMP_DECLSPEC void mpf_sqrt_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_sub __gmpf_sub +__GMP_DECLSPEC void mpf_sub __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_sub_ui __gmpf_sub_ui +__GMP_DECLSPEC void mpf_sub_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_swap __gmpf_swap +__GMP_DECLSPEC void mpf_swap __GMP_PROTO ((mpf_ptr, mpf_ptr)) __GMP_NOTHROW; +#define mpf_trunc __gmpf_trunc +__GMP_DECLSPEC void mpf_trunc __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_ui_div __gmpf_ui_div +__GMP_DECLSPEC void mpf_ui_div __GMP_PROTO ((mpf_ptr, mpir_ui, mpf_srcptr)); +#define mpf_ui_sub __gmpf_ui_sub +__GMP_DECLSPEC void mpf_ui_sub __GMP_PROTO ((mpf_ptr, mpir_ui, mpf_srcptr)); +#define mpf_urandomb __gmpf_urandomb +__GMP_DECLSPEC void mpf_urandomb __GMP_PROTO ((mpf_t, gmp_randstate_t, mp_bitcnt_t)); +/************ Low level positive-integer (i.e. N) routines. ************/ +/* This is ugly, but we need to make user calls reach the prefixed function. */ +#define mpn_add __MPN(add) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add) +__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif +#define mpn_add_1 __MPN(add_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1) +__GMP_DECLSPEC mp_limb_t mpn_add_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif +#define mpn_add_n __MPN(add_n) +__GMP_DECLSPEC mp_limb_t mpn_add_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_addmul_1 __MPN(addmul_1) +__GMP_DECLSPEC mp_limb_t mpn_addmul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_bdivmod __MPN(bdivmod) +__GMP_DECLSPEC mp_limb_t mpn_bdivmod __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mpir_ui)); +#define mpn_divrem __MPN(divrem) +__GMP_DECLSPEC mp_limb_t mpn_divrem __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_mulmod_Bexpp1 __MPN(mulmod_Bexpp1) +__GMP_DECLSPEC int mpn_mulmod_Bexpp1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_ptr)); +#define mpn_mulmod_2expp1 __MPN(mulmod_2expp1_basecase) +__GMP_DECLSPEC int mpn_mulmod_2expp1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr,int,mpir_ui, mp_ptr)); +#define mpn_mulmod_2expm1 __MPN(mulmod_2expm1) +__GMP_DECLSPEC void mpn_mulmod_2expm1 __GMP_PROTO ((mp_ptr, mp_ptr, mp_ptr, mpir_ui, mp_ptr)); +#define mpn_cmp __MPN(cmp) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp) +__GMP_DECLSPEC int mpn_cmp __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpn_redc_1 __MPN(redc_1) +__GMP_DECLSPEC void mpn_redc_1 __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);) +#define mpn_redc_2 __MPN(redc_2) +__GMP_DECLSPEC void mpn_redc_2 __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr)); +#define mpn_redc_n __MPN(redc_n) +__GMP_DECLSPEC void mpn_redc_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr)); +#define mpn_divexact_by3(dst,src,size) \ + mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0)) +#define mpn_divexact_by3c __MPN(divexact_by3c) +__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_divmod_1(qp,np,nsize,dlimb) \ + mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb) +#define mpn_divrem_1 __MPN(divrem_1) +__GMP_DECLSPEC mp_limb_t mpn_divrem_1 __GMP_PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_divrem_2 __MPN(divrem_2) +__GMP_DECLSPEC mp_limb_t mpn_divrem_2 __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr)); +#define mpn_invert __MPN(invert) +__GMP_DECLSPEC void mpn_invert __GMP_PROTO ((mp_ptr xp, mp_srcptr ap, mp_size_t n)); +#define mpn_sb_divappr_q __MPN(sb_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_sb_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dip)); +#define mpn_dc_bdiv_q_n __MPN(dc_bdiv_q_n) +__GMP_DECLSPEC void mpn_dc_bdiv_q_n __GMP_PROTO ((mp_ptr qp, mp_ptr wp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_limb_t dinv, mp_ptr scratch)); +#define mpn_inv_divappr_q_n __MPN(inv_divappr_q_n) +__GMP_DECLSPEC mp_limb_t mpn_inv_divappr_q_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_srcptr dip)); +#define mpn_dc_divappr_q __MPN(dc_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_dc_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, + mp_size_t n, mp_limb_t dinv)); +#define mpn_dc_div_q __MPN(dc_div_q) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_inv_divappr_q __MPN(inv_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_inv_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, mp_size_t n, + mp_srcptr dinv)); +#define mpn_inv_div_q __MPN(inv_div_q) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_inv_div_qr __MPN(inv_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_inv_div_qr_n __MPN(inv_div_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_dc_div_qr __MPN(dc_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_div_qr_n __MPN(dc_div_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_limb_t dinv, mp_ptr tp)); +#define mpn_sb_div_q __MPN(sb_div_q) +__GMP_DECLSPEC mp_limb_t mpn_sb_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_sb_bdiv_q __MPN(sb_bdiv_q) +__GMP_DECLSPEC void mpn_sb_bdiv_q __GMP_PROTO ((mp_ptr qp, mp_ptr wp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_q __MPN(dc_bdiv_q) +__GMP_DECLSPEC void mpn_dc_bdiv_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_qr __MPN(dc_bdiv_qr) +__GMP_DECLSPEC mp_limb_t mpn_dc_bdiv_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_qr_n __MPN(dc_bdiv_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_dc_bdiv_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, + mp_srcptr dp, mp_size_t n, mp_limb_t dinv, mp_ptr tp)); +#define mpn_sb_div_qr __MPN(sb_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_sb_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_sb_bdiv_qr __MPN(sb_bdiv_qr) +__GMP_DECLSPEC mp_limb_t mpn_sb_bdiv_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_tdiv_q __MPN(tdiv_q) +__GMP_DECLSPEC void mpn_tdiv_q __GMP_PROTO ((mp_ptr qp, mp_srcptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn)); +#define mpn_divexact __MPN(divexact) +__GMP_DECLSPEC void mpn_divexact __GMP_PROTO ((mp_ptr qp, + mp_srcptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn)); +#define mpn_gcd __MPN(gcd) +__GMP_DECLSPEC mp_size_t mpn_gcd __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); +#define mpn_gcd_1 __MPN(gcd_1) +__GMP_DECLSPEC mp_limb_t mpn_gcd_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_gcdext_1 __MPN(gcdext_1) +__GMP_DECLSPEC mp_limb_t mpn_gcdext_1 __GMP_PROTO ((mp_limb_signed_t *, mp_limb_signed_t *, mp_limb_t, mp_limb_t)); +#define mpn_gcdext __MPN(gcdext) +__GMP_DECLSPEC mp_size_t mpn_gcdext __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); +#define mpn_get_str __MPN(get_str) +__GMP_DECLSPEC size_t mpn_get_str __GMP_PROTO ((unsigned char *, int, mp_ptr, mp_size_t)); +#define mpn_hamdist __MPN(hamdist) +__GMP_DECLSPEC mp_bitcnt_t mpn_hamdist __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpn_lshift __MPN(lshift) +__GMP_DECLSPEC mp_limb_t mpn_lshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); +#define mpn_mod_1 __MPN(mod_1) +__GMP_DECLSPEC mp_limb_t mpn_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_mul __MPN(mul) +__GMP_DECLSPEC mp_limb_t mpn_mul __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_mul_1 __MPN(mul_1) +__GMP_DECLSPEC mp_limb_t mpn_mul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_mul_n __MPN(mul_n) +__GMP_DECLSPEC void mpn_mul_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_sqr __MPN(sqr) +__GMP_DECLSPEC void mpn_sqr __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_neg_n __MPN(neg_n) +#define mpn_neg __MPN(neg_n) +__GMP_DECLSPEC mp_limb_t mpn_neg_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_com_n __MPN(com_n) +#define mpn_com __MPN(com_n) +__GMP_DECLSPEC void mpn_com_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_perfect_square_p __MPN(perfect_square_p) +__GMP_DECLSPEC int mpn_perfect_square_p __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_popcount __MPN(popcount) +__GMP_DECLSPEC mp_bitcnt_t mpn_popcount __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpn_pow_1 __MPN(pow_1) +__GMP_DECLSPEC mp_size_t mpn_pow_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr)); +/* undocumented now, but retained here for upward compatibility */ +#define mpn_preinv_mod_1 __MPN(preinv_mod_1) +__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_random __MPN(random) +__GMP_DECLSPEC void mpn_random __GMP_PROTO ((mp_ptr, mp_size_t)); +#define mpn_random2 __MPN(random2) +__GMP_DECLSPEC void mpn_random2 __GMP_PROTO ((mp_ptr, mp_size_t)); +#define mpn_urandomb __MPN(urandomb) +__GMP_DECLSPEC void mpn_urandomb __GMP_PROTO ((mp_ptr, gmp_randstate_t, mpir_ui)); +#define mpn_urandomm __MPN(urandomm) +__GMP_DECLSPEC void mpn_urandomm __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_srcptr, mp_size_t)); +#define mpn_randomb __MPN(randomb) +__GMP_DECLSPEC void mpn_randomb __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_size_t)); +#define mpn_rrandom __MPN(rrandom) +__GMP_DECLSPEC void mpn_rrandom __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_size_t)); +#define mpn_rshift __MPN(rshift) +__GMP_DECLSPEC mp_limb_t mpn_rshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); +#define mpn_scan0 __MPN(scan0) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan0 __GMP_PROTO ((mp_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_scan1 __MPN(scan1) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan1 __GMP_PROTO ((mp_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_set_str __MPN(set_str) +__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned char *, size_t, int)); +#define mpn_sizeinbase __MPN(sizeinbase) +__GMP_DECLSPEC size_t mpn_sizeinbase (mp_srcptr, mp_size_t, int); +#define mpn_sqrtrem __MPN(sqrtrem) +__GMP_DECLSPEC mp_size_t mpn_sqrtrem __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_sub __MPN(sub) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub) +__GMP_DECLSPEC mp_limb_t mpn_sub __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif +#define mpn_sub_1 __MPN(sub_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1) +__GMP_DECLSPEC mp_limb_t mpn_sub_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif +#define mpn_sub_n __MPN(sub_n) +__GMP_DECLSPEC mp_limb_t mpn_sub_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_submul_1 __MPN(submul_1) +__GMP_DECLSPEC mp_limb_t mpn_submul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_tdiv_qr __MPN(tdiv_qr) +__GMP_DECLSPEC void mpn_tdiv_qr __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_and_n __MPN(and_n) +__GMP_DECLSPEC void mpn_and_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_andn_n __MPN(andn_n) +__GMP_DECLSPEC void mpn_andn_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_nand_n __MPN(nand_n) +__GMP_DECLSPEC void mpn_nand_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_ior_n __MPN(ior_n) +__GMP_DECLSPEC void mpn_ior_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_iorn_n __MPN(iorn_n) +__GMP_DECLSPEC void mpn_iorn_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_nior_n __MPN(nior_n) +__GMP_DECLSPEC void mpn_nior_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_xor_n __MPN(xor_n) +__GMP_DECLSPEC void mpn_xor_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_xnor_n __MPN(xnor_n) +__GMP_DECLSPEC void mpn_xnor_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_copyi __MPN(copyi) +__GMP_DECLSPEC void mpn_copyi __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_copyd __MPN(copyd) +__GMP_DECLSPEC void mpn_copyd __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_zero __MPN(zero) +__GMP_DECLSPEC void mpn_zero __GMP_PROTO ((mp_ptr, mp_size_t)); +#ifndef mpn_sumdiff_n /* if not done with cpuvec in a fat binary of in gmp-impl.h*/ +#define mpn_sumdiff_n __MPN(sumdiff_n) +__GMP_DECLSPEC mp_limb_t mpn_sumdiff_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#endif +#ifndef mpn_nsumdiff_n /* if not done with cpuvec in a fat binary of in gmp-impl.h*/ +#define mpn_nsumdiff_n __MPN(nsumdiff_n) +__GMP_DECLSPEC mp_limb_t mpn_nsumdiff_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#endif +/**************** MPN API for FFT ****************/ +#define mpn_mul_fft_main __MPN(mul_fft_main) +__GMP_DECLSPEC void mpn_mul_fft_main __GMP_PROTO ((mp_ptr r1, mp_srcptr i1, mp_size_t n1, mp_srcptr i2, mp_size_t n2)); +#define mpn_mul_fft __MPN(mul_fft) +__GMP_DECLSPEC int mpn_mul_fft __GMP_PROTO((mp_ptr rp, mp_size_t rn, mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn, int k)); +/**************** mpz inlines ****************/ +/* The following are provided as inlines where possible, but always exist as + library functions too, for binary compatibility. + Within gmp itself this inlining generally isn't relied on, since it + doesn't get done for all compilers, whereas if something is worth + inlining then it's worth arranging always. + There are two styles of inlining here. When the same bit of code is + wanted for the inline as for the library version, then __GMP_FORCE_foo + arranges for that code to be emitted and the __GMP_EXTERN_INLINE + directive suppressed, eg. mpz_fits_uint_p. When a different bit of code + is wanted for the inline than for the library version, then + __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */ +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs) +__GMP_EXTERN_INLINE void +mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size); +} +#endif +#if GMP_NAIL_BITS == 0 +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)); +#else +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \ + || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS))); +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p) +#if ! defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_UINT_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ui_p) +#if ! defined (__GMP_FORCE_mpz_fits_ui_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ui_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, GMP_UI_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p) +#if ! defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_ULONG_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p) +#if ! defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_USHRT_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui) +#if ! defined (__GMP_FORCE_mpz_get_ui) +__GMP_EXTERN_INLINE +#endif +mpir_ui +mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + mp_ptr __gmp_p = __gmp_z->_mp_d; + mp_size_t __gmp_n = __gmp_z->_mp_size; + mp_limb_t __gmp_l = __gmp_p[0]; + /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings + about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland + C++ 6.0 warnings about condition always true for something like + "__GMP_ULONG_MAX < GMP_NUMB_MASK". */ +#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB) + /* limb==long and no nails, or limb==longlong, one limb is enough */ + return (mpir_ui)(__gmp_n != 0 ? __gmp_l : 0); +#else + /* limb==long and nails, need two limbs when available */ + __gmp_n = __GMP_ABS (__gmp_n); + if (__gmp_n <= 1) + return (mpir_ui)(__gmp_n != 0 ? __gmp_l : 0); + else + return (mpir_ui)(__gmp_l + (__gmp_p[1] << GMP_NUMB_BITS)); +#endif +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn) +#if ! defined (__GMP_FORCE_mpz_getlimbn) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_result = 0; + if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size))) + __gmp_result = __gmp_z->_mp_d[__gmp_n]; + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg) +__GMP_EXTERN_INLINE void +mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = - __gmp_w->_mp_size; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p) +#if ! defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_perfect_square_p (mpz_srcptr __gmp_a) +{ + mp_size_t __gmp_asize; + int __gmp_result; + __gmp_asize = __gmp_a->_mp_size; + __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */ + if (__GMP_LIKELY (__gmp_asize > 0)) + __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount) +#if ! defined (__GMP_FORCE_mpz_popcount) +__GMP_EXTERN_INLINE +#endif +mp_bitcnt_t +mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW +{ + mp_size_t __gmp_usize; + mp_bitcnt_t __gmp_result; + __gmp_usize = __gmp_u->_mp_size; + __gmp_result = (__gmp_usize < 0 ? __GMP_BITCNT_MAX : 0); + if (__GMP_LIKELY (__gmp_usize > 0)) + __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q) +#if ! defined (__GMP_FORCE_mpz_set_q) +__GMP_EXTERN_INLINE +#endif +void +mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u)); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size) +#if ! defined (__GMP_FORCE_mpz_size) +__GMP_EXTERN_INLINE +#endif +size_t +mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + return __GMP_ABS (__gmp_z->_mp_size); +} +#endif +/**************** mpq inlines ****************/ +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs) +__GMP_EXTERN_INLINE void +mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size); +} +#endif +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg) +__GMP_EXTERN_INLINE void +mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size; +} +#endif +/**************** mpn inlines ****************/ +/* The comments with __GMPN_ADD_1 below apply here too. + The test for FUNCTION returning 0 should predict well. If it's assumed + {yp,ysize} will usually have a random number of bits then the high limb + won't be full and a carry out will occur a good deal less than 50% of the + time. + ysize==0 isn't a documented feature, but is used internally in a few + places. + Producing cout last stops it using up a register during the main part of + the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))" + doesn't seem able to move the true and false legs of the conditional up + to the two places cout is generated. */ +#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x; \ + \ + /* ASSERT ((ysize) >= 0); */ \ + /* ASSERT ((xsize) >= (ysize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \ + \ + __gmp_i = (ysize); \ + if (__gmp_i != 0) \ + { \ + if (FUNCTION (wp, xp, yp, __gmp_i)) \ + { \ + do \ + { \ + if (__gmp_i >= (xsize)) \ + { \ + (cout) = 1; \ + goto __gmp_done; \ + } \ + __gmp_x = (xp)[__gmp_i]; \ + } \ + while (TEST); \ + } \ + } \ + if ((wp) != (xp)) \ + __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \ + (cout) = 0; \ + __gmp_done: \ + ; \ + } while (0) +#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \ + (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0)) +#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \ + (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0)) +/* The use of __gmp_i indexing is designed to ensure a compile time src==dst + remains nice and clear to the compiler, so that __GMPN_COPY_REST can + disappear, and the load/add/store gets a chance to become a + read-modify-write on CISC CPUs. + Alternatives: + Using a pair of pointers instead of indexing would be possible, but gcc + isn't able to recognise compile-time src==dst in that case, even when the + pointers are incremented more or less together. Other compilers would + very likely have similar difficulty. + gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or + similar to detect a compile-time src==dst. This works nicely on gcc + 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems + to be always false, for a pointer p. But the current code form seems + good enough for src==dst anyway. + gcc on x86 as usual doesn't give particularly good flags handling for the + carry/borrow detection. It's tempting to want some multi instruction asm + blocks to help it, and this was tried, but in truth there's only a few + instructions to save and any gain is all too easily lost by register + juggling setting up for the asm. */ +#if GMP_NAIL_BITS == 0 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r; \ + if (CB (__gmp_r, __gmp_x, (v))) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r; \ + ++__gmp_i; \ + if (!CB (__gmp_r, __gmp_x, 1)) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif +#if GMP_NAIL_BITS >= 1 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r & GMP_NUMB_MASK; \ + if (__gmp_r >> GMP_NUMB_BITS != 0) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \ + ++__gmp_i; \ + if (__gmp_r >> GMP_NUMB_BITS == 0) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif +#define __GMPN_ADDCB(r,x,y) ((r) < (y)) +#define __GMPN_SUBCB(r,x,y) ((x) < (y)) +#define __GMPN_ADD_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB) +#define __GMPN_SUB_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB) +/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or + negative. size==0 is allowed. On random data usually only one limb will + need to be examined to get a result, so it's worth having it inline. */ +#define __GMPN_CMP(result, xp, yp, size) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_y; \ + \ + /* ASSERT ((size) >= 0); */ \ + \ + (result) = 0; \ + __gmp_i = (size); \ + while (--__gmp_i >= 0) \ + { \ + __gmp_x = (xp)[__gmp_i]; \ + __gmp_y = (yp)[__gmp_i]; \ + if (__gmp_x != __gmp_y) \ + { \ + /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \ + (result) = (__gmp_x > __gmp_y ? 1 : -1); \ + break; \ + } \ + } \ + } while (0) +#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \ + } while (0) +#endif +/* Copy {src,size} to {dst,size}, starting at "start". This is designed to + keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1, + __GMPN_ADD, etc. */ +#if ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + mp_size_t __gmp_j; \ + /* ASSERT ((size) >= 0); */ \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \ + for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \ + (dst)[__gmp_j] = (src)[__gmp_j]; \ + } while (0) +#endif +/* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use + mpn_copyi if there's a native version, and if we don't mind demanding + binary compatibility for it (on targets which use it). */ +#if ! defined (__GMPN_COPY) +#define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0) +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add) +#if ! defined (__GMP_FORCE_mpn_add) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1) +#if ! defined (__GMP_FORCE_mpn_add_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp) +#if ! defined (__GMP_FORCE_mpn_cmp) +__GMP_EXTERN_INLINE +#endif +int +mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW +{ + int __gmp_result; + __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub) +#if ! defined (__GMP_FORCE_mpn_sub) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1) +#if ! defined (__GMP_FORCE_mpn_sub_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif +#if defined (__cplusplus) +} +#endif +/* Allow faster testing for negative, zero, and positive. */ +#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) +#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) +#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) +/* When using GCC, optimize certain common comparisons. */ +#if defined (__GNUC__) +#define mpz_cmp_ui(Z,UI) \ + (__builtin_constant_p (UI) && (UI) == 0 \ + ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) +#define mpz_cmp_si(Z,SI) \ + (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z) \ + : __builtin_constant_p (SI) && (SI) > 0 \ + ? _mpz_cmp_ui (Z, __GMP_CAST (unsigned long int, SI)) \ + : _mpz_cmp_si (Z,SI)) +#define mpq_cmp_ui(Q,NUI,DUI) \ + (__builtin_constant_p (NUI) && (NUI) == 0 \ + ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI)) +#define mpq_cmp_si(q,n,d) \ + (__builtin_constant_p ((n) >= 0) && (n) >= 0 \ + ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \ + : _mpq_cmp_si (q, n, d)) +#else +#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) +#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) +#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) +#define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d) +#endif +/* Using "&" rather than "&&" means these can come out branch-free. Every + mpz_t has at least one limb allocated, so fetching the low limb is always + allowed. */ +#define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0])) +#define mpz_even_p(z) (! mpz_odd_p (z)) +/**************** C++ routines ****************/ +#ifdef __cplusplus +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr); +#endif +/* Source-level compatibility with GMP 1. */ +#define mpz_mdiv mpz_fdiv_q +#define mpz_mdivmod mpz_fdiv_qr +#define mpz_mmod mpz_fdiv_r +#define mpz_mdiv_ui mpz_fdiv_q_ui +#define mpz_mdivmod_ui(q,r,n,d) \ + (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) +#define mpz_mmod_ui(r,n,d) \ + (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) +#define gmp_randinit(x,y,z) gmp_randinit_lc_2exp_size(x,z) +typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */ +typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */ +#define mpz_div mpz_fdiv_q +#define mpz_divmod mpz_fdiv_qr +#define mpz_div_ui mpz_fdiv_q_ui +#define mpz_divmod_ui mpz_fdiv_qr_ui +#define mpz_div_2exp mpz_fdiv_q_2exp +#define mpz_mod_2exp mpz_fdiv_r_2exp +enum +{ + GMP_ERROR_NONE = 0, + GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, + GMP_ERROR_DIVISION_BY_ZERO = 2, + GMP_ERROR_SQRT_OF_NEGATIVE = 4, + GMP_ERROR_INVALID_ARGUMENT = 8 +}; +/* Major version number is the value of __GNU_MP__ too, above and in mp.h. */ +#define __GNU_MP_VERSION 6 +#define __GNU_MP_VERSION_MINOR 0 +#define __GNU_MP_VERSION_PATCHLEVEL 0 +#define GMP_VERSION "6.0.0" +#define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL) +#define __MPIR_VERSION 3 +#define __MPIR_VERSION_MINOR 0 +#define __MPIR_VERSION_PATCHLEVEL 0 +#if defined( _MSC_VER ) +#define _MSC_MPIR_VERSION "3.0.0" +#endif +#define __MPIR_RELEASE (__MPIR_VERSION * 10000 + __MPIR_VERSION_MINOR * 100 + __MPIR_VERSION_PATCHLEVEL) +/* These are for programs like MPFR to use the same CC and CFLAGS as MPIR */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#endif +#define __GMP_H__ +#endif /* __GMP_H__ */ diff --git a/include/mpir_x64-windows/include/gmpxx.h b/include/mpir_x64-windows/include/gmpxx.h new file mode 100644 index 0000000..f69cb48 --- /dev/null +++ b/include/mpir_x64-windows/include/gmpxx.h @@ -0,0 +1,3675 @@ +/* gmpxx.h -- C++ class wrapper for GMP types. -*- C++ -*- + +Copyright 2001, 2002, 2003, 2006, 2008, 2011, 2012 Free Software Foundation, +Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ + +/* the C++ compiler must implement the following features: + - member templates + - partial specialization of templates + - namespace support + for g++, this means version 2.91 or higher + for other compilers, I don't know */ +#ifdef __GNUC__ +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 91) +#error mpirxx.h requires g++ version 2.91 (egcs 1.1.2) or higher +#endif +#endif +#ifndef __GMP_PLUSPLUS__ +#define __GMP_PLUSPLUS__ + +#include /* for size_t */ + +#include + +#include /* for strlen */ +#include /* numeric_limits */ +#include +#include +#include +#include +#include /* swap */ +#include + +#if defined( _MSC_VER ) && _MSC_VER >= 1700 +# define MSC_CXX_11 1 +#elif defined( __INTEL_COMPILER ) && __INTEL_COMPILER > 1310 +# define MSC_CXX_11 1 +#elif defined( __ICL ) && __ICL > 1310 +# define MSC_CXX_11 1 +#endif + +#if defined(LLONG_MAX) && defined(LONG_MAX) +#if LLONG_MAX != LONG_MAX +#define MPIRXX_HAVE_LLONG 1 +#endif +#endif + +/* check availability of stdint.h -- note we do not include this ourselves */ +#if defined(INTMAX_MAX) +# if defined(LONG_MAX) && defined(INTMAX_MAX) && INTMAX_MAX != LONG_MAX && (INTMAX_MAX != LLONG_MAX || !defined(MPIRXX_HAVE_LLONG)) +# define MPIRXX_INTMAX_T 1 +# endif +# if defined(ULONG_MAX) && defined(UINTMAX_MAX) && UINTMAX_MAX != ULONG_MAX && (UINTMAX_MAX != ULLONG_MAX || !defined(MPIRXX_HAVE_LLONG)) +# define MPIRXX_UINTMAX_T 1 +# endif +#endif + +// wrapper for gcc's __builtin_constant_p +// __builtin_constant_p has been in gcc since forever, +// but g++-3.4 miscompiles it. +#if __GMP_GNUC_PREREQ(4, 2) +#define __GMPXX_CONSTANT(X) __builtin_constant_p(X) +#else +#define __GMPXX_CONSTANT(X) false +#endif + +// Use C++11 features +#ifndef __GMPXX_USE_CXX11 +#if __cplusplus >= 201103L +#define __GMPXX_USE_CXX11 1 +#else +#define __GMPXX_USE_CXX11 0 +#endif +#endif + +#if __GMPXX_USE_CXX11 +#define __GMPXX_NOEXCEPT noexcept +#include // for common_type +#else +#define __GMPXX_NOEXCEPT +#endif + +// Max allocations for plain types when converted to mpz_t +#define __GMPZ_DBL_LIMBS (2 + DBL_MAX_EXP / GMP_NUMB_BITS) + +#if GMP_NAIL_BITS != 0 && ! defined _LONG_LONG_LIMB +#define __GMPZ_ULI_LIMBS 2 +#else +#define __GMPZ_ULI_LIMBS 1 +#endif + +inline void __mpz_set_ui_safe(mpz_ptr p, mpir_ui l) +{ + p->_mp_size = (l != 0); + p->_mp_d[0] = l & GMP_NUMB_MASK; +#if __GMPZ_ULI_LIMBS > 1 + l >>= GMP_NUMB_BITS; + p->_mp_d[1] = l; + p->_mp_size += (l != 0); +#endif +} + +inline void __mpz_set_si_safe(mpz_ptr p, mpir_si l) +{ + if(l < 0) + { + __mpz_set_ui_safe(p, static_cast(-l)); + mpz_neg(p, p); + } + else + __mpz_set_ui_safe(p, l); + // Note: we know the high bit of l is 0 so we could do slightly better +} + +// Fake temporary variables +#define __GMPXX_TMPZ_UI \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS]; \ + temp->_mp_d = limbs; \ + __mpz_set_ui_safe (temp, l) +#define __GMPXX_TMPZ_SI \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS]; \ + temp->_mp_d = limbs; \ + __mpz_set_si_safe (temp, l) +#define __GMPXX_TMPZ_D \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_DBL_LIMBS]; \ + temp->_mp_d = limbs; \ + temp->_mp_alloc = __GMPZ_DBL_LIMBS; \ + mpz_set_d (temp, d) + +#define __GMPXX_TMPQ_UI \ + mpq_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS+1]; \ + mpq_numref(temp)->_mp_d = limbs; \ + __mpz_set_ui_safe (mpq_numref(temp), l); \ + mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS; \ + mpq_denref(temp)->_mp_size = 1; \ + mpq_denref(temp)->_mp_d[0] = 1 +#define __GMPXX_TMPQ_SI \ + mpq_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS+1]; \ + mpq_numref(temp)->_mp_d = limbs; \ + __mpz_set_si_safe (mpq_numref(temp), l); \ + mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS; \ + mpq_denref(temp)->_mp_size = 1; \ + mpq_denref(temp)->_mp_d[0] = 1 + +inline mpir_ui __gmpxx_abs_ui (mpir_si l) +{ + return l >= 0 ? static_cast(l) + : static_cast(-l); +} + +/**************** Function objects ****************/ +/* Any evaluation of a __gmp_expr ends up calling one of these functions + all intermediate functions being inline, the evaluation should optimize + to a direct call to the relevant function, thus yielding no overhead + over the C interface. */ + +struct __gmp_unary_plus +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_set(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_set(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_set(f, g); } +}; + +struct __gmp_unary_minus +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_neg(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_neg(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_neg(f, g); } +}; + +struct __gmp_unary_com +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_com(z, w); } +}; + +struct __gmp_binary_plus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_add(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + // Ideally, those checks should happen earlier so that the tree + // generated for a+0+b would just be sum(a,b). + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (z != w) mpz_set(z, w); + } + else + mpz_add_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + mpz_sub_ui(z, w, static_cast(-l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_add (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_add(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (q != r) mpq_set(q, r); + } + else + { + if (q == r) + mpz_addmul_ui(mpq_numref(q), mpq_denref(q), l); + else + { + mpz_mul_ui(mpq_numref(q), mpq_denref(r), l); + mpz_add(mpq_numref(q), mpq_numref(q), mpq_numref(r)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); } + static inline void eval(mpq_ptr q, mpq_srcptr r, mpir_si l); + // defined after __gmp_binary_minus + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_add(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { eval(q, r, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z) + { + if (q == r) + mpz_addmul(mpq_numref(q), mpq_denref(q), z); + else + { + mpz_mul(mpq_numref(q), mpq_denref(r), z); + mpz_add(mpq_numref(q), mpq_numref(q), mpq_numref(r)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r) + { eval(q, r, z); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_add(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_add_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_add_ui(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_add_ui(f, g, l); + else + mpf_sub_ui(f, g, static_cast(-l)); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_add(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_binary_minus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_sub(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (z != w) mpz_set(z, w); + } + else + mpz_sub_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + mpz_neg(z, w); + } + else + mpz_ui_sub(z, l, w); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + mpz_add_ui(z, w, static_cast(-l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (l >= 0) + eval(z, static_cast(l), w); + else + { + mpz_add_ui(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_sub (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_sub (z, temp, w); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_sub(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (q != r) mpq_set(q, r); + } + else + { + if (q == r) + mpz_submul_ui(mpq_numref(q), mpq_denref(q), l); + else + { + mpz_mul_ui(mpq_numref(q), mpq_denref(r), l); + mpz_sub(mpq_numref(q), mpq_numref(r), mpq_numref(q)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); mpq_neg(q, q); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + __gmp_binary_plus::eval(q, r, static_cast(-l)); + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); mpq_neg(q, q); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_sub(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_sub(q, temp, r); + mpq_clear(temp); + } + + static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z) + { + if (q == r) + mpz_submul(mpq_numref(q), mpq_denref(q), z); + else + { + mpz_mul(mpq_numref(q), mpq_denref(r), z); + mpz_sub(mpq_numref(q), mpq_numref(r), mpq_numref(q)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r) + { eval(q, r, z); mpq_neg(q, q); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_sub(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_sub_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_ui_sub(f, l, g); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_sub_ui(f, g, l); + else + mpf_add_ui(f, g, static_cast(-l)); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { + if (l >= 0) + mpf_sub_ui(f, g, l); + else + mpf_add_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_sub(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_sub(f, temp, g); + mpf_clear(temp); + } +}; + +// defined here so it can reference __gmp_binary_minus +inline void +__gmp_binary_plus::eval(mpq_ptr q, mpq_srcptr r, mpir_si l) +{ + if (l >= 0) + eval(q, r, static_cast(l)); + else + __gmp_binary_minus::eval(q, r, static_cast(-l)); +} + +struct __gmp_binary_lshift +{ + static void eval(mpz_ptr z, mpz_srcptr w, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (z != w) mpz_set(z, w); + } + else + mpz_mul_2exp(z, w, l); + } + static void eval(mpq_ptr q, mpq_srcptr r, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (q != r) mpq_set(q, r); + } + else + mpq_mul_2exp(q, r, l); + } + static void eval(mpf_ptr f, mpf_srcptr g, mp_bitcnt_t l) + { mpf_mul_2exp(f, g, l); } +}; + +struct __gmp_binary_rshift +{ + static void eval(mpz_ptr z, mpz_srcptr w, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (z != w) mpz_set(z, w); + } + else + mpz_fdiv_q_2exp(z, w, l); + } + static void eval(mpq_ptr q, mpq_srcptr r, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (q != r) mpq_set(q, r); + } + else + mpq_div_2exp(q, r, l); + } + static void eval(mpf_ptr f, mpf_srcptr g, mp_bitcnt_t l) + { mpf_div_2exp(f, g, l); } +}; + +struct __gmp_binary_multiplies +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_mul(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { +// gcc-3.3 doesn't have __builtin_ctzl. Don't bother optimizing for old gcc. +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0) + { + if (l == 0) + { + z->_mp_size = 0; + } + else + { + __gmp_binary_lshift::eval(z, w, __builtin_ctzl(l)); + } + } + else +#endif + mpz_mul_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + { + eval(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + else + mpz_mul_si (z, w, l); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_mul (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_mul(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0) + { + if (l == 0) + { + mpq_set_ui(q, 0, 1); + } + else + { + __gmp_binary_lshift::eval(q, r, __builtin_ctzl(l)); + } + } + else +#endif + { + __GMPXX_TMPQ_UI; + mpq_mul (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + { + eval(q, r, static_cast(-l)); + mpq_neg(q, q); + } + } + else + { + __GMPXX_TMPQ_SI; + mpq_mul (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_mul(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { eval(q, r, d); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_mul(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_mul_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_mul_ui(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_mul_ui(f, g, l); + else + { + mpf_mul_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_mul(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_binary_divides +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_tdiv_q(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + // Don't optimize division by 0... + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0 && l != 0) + { + if (l == 1) + { + if (z != w) mpz_set(z, w); + } + else + mpz_tdiv_q_2exp(z, w, __builtin_ctzl(l)); + // warning: do not use rshift (fdiv) + } + else +#endif + mpz_tdiv_q_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (mpz_sgn(w) >= 0) + { + if (mpz_fits_ui_p(w)) + mpz_set_ui(z, l / mpz_get_ui(w)); + else + mpz_set_ui(z, 0); + } + else + { + mpz_neg(z, w); + if (mpz_fits_ui_p(z)) + { + mpz_set_ui(z, l / mpz_get_ui(z)); + mpz_neg(z, z); + } + else + mpz_set_ui(z, 0); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + { + eval(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (mpz_fits_si_p(w)) + mpz_set_si(z, l / mpz_get_si(w)); + else + { + /* if w is bigger than a long then the quotient must be zero, unless + l==LONG_MIN and w==-LONG_MIN in which case the quotient is -1 */ + mpz_set_si (z, (mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? -1 : 0)); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_tdiv_q (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_tdiv_q (z, temp, w); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_div(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0 && l != 0) + __gmp_binary_rshift::eval(q, r, __builtin_ctzl(l)); + else +#endif + { + __GMPXX_TMPQ_UI; + mpq_div (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { __GMPXX_TMPQ_UI; mpq_div (q, temp, r); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + { + eval(q, r, static_cast(-l)); + mpq_neg(q, q); + } + } + else + { + __GMPXX_TMPQ_SI; + mpq_div (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { __GMPXX_TMPQ_SI; mpq_div (q, temp, r); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_div(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_div(q, temp, r); + mpq_clear(temp); + } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_div(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_div_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_ui_div(f, l, g); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_div_ui(f, g, l); + else + { + mpf_div_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { + if (l >= 0) + mpf_ui_div(f, l, g); + else + { + mpf_ui_div(f, static_cast(-l), g); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_div(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_div(f, temp, g); + mpf_clear(temp); + } +}; + +struct __gmp_binary_modulus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_tdiv_r(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { mpz_tdiv_r_ui(z, w, l); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (mpz_sgn(w) >= 0) + { + if (mpz_fits_ui_p(w)) + mpz_set_ui(z, l % mpz_get_ui(w)); + else + mpz_set_ui(z, l); + } + else + { + mpz_neg(z, w); + if (mpz_fits_ui_p(z)) + mpz_set_ui(z, l % mpz_get_ui(z)); + else + mpz_set_ui(z, l); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + mpz_tdiv_r_ui (z, w, (l >= 0 ? l : -l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (mpz_fits_si_p(w)) + mpz_set_si(z, l % mpz_get_si(w)); + else + { + /* if w is bigger than a long then the remainder is l unchanged, + unless l==LONG_MIN and w==-LONG_MIN in which case it's 0 */ + mpz_set_si (z, mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? 0 : l); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_tdiv_r (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_tdiv_r (z, temp, w); } +}; + +struct __gmp_binary_and +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_and(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_ior +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_ior(z, w, v); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_xor +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_xor(z, w, v); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_equal +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) == 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) == 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) == 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) == 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) == 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) == 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) == 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) + { return mpq_equal(q, r) != 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) == 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) == 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) == 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) == 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_equal(q, temp) != 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + return eval(q, d); + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) == 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) == 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) == 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) == 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) == 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) == 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) == 0; } +}; + +struct __gmp_binary_less +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) < 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) < 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) > 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) < 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) > 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) < 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) > 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) < 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) < 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) > 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) < 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) > 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(q, temp) < 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(temp, q) < 0); + mpq_clear(temp); + return b; + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) < 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) < 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) > 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) < 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) > 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) < 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) > 0; } +}; + +struct __gmp_binary_greater +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) > 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) > 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) < 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) > 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) < 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) > 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) < 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) > 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) > 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) < 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) > 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) < 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(q, temp) > 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(temp, q) > 0); + mpq_clear(temp); + return b; + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) > 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) > 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) < 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) > 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) < 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) > 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) < 0; } +}; + +struct __gmp_unary_increment +{ + static void eval(mpz_ptr z) { mpz_add_ui(z, z, 1); } + static void eval(mpq_ptr q) + { mpz_add(mpq_numref(q), mpq_numref(q), mpq_denref(q)); } + static void eval(mpf_ptr f) { mpf_add_ui(f, f, 1); } +}; + +struct __gmp_unary_decrement +{ + static void eval(mpz_ptr z) { mpz_sub_ui(z, z, 1); } + static void eval(mpq_ptr q) + { mpz_sub(mpq_numref(q), mpq_numref(q), mpq_denref(q)); } + static void eval(mpf_ptr f) { mpf_sub_ui(f, f, 1); } +}; + +struct __gmp_abs_function +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_abs(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_abs(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_abs(f, g); } +}; + +struct __gmp_trunc_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_trunc(f, g); } +}; + +struct __gmp_floor_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_floor(f, g); } +}; + +struct __gmp_ceil_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_ceil(f, g); } +}; + +struct __gmp_sqrt_function +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_sqrt(z, w); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_sqrt(f, g); } +}; + +struct __gmp_hypot_function +{ + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_mul(f, h, h); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_ui(f, l); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_si(f, l); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_d(f, d); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_sgn_function +{ + static int eval(mpz_srcptr z) { return mpz_sgn(z); } + static int eval(mpq_srcptr q) { return mpq_sgn(q); } + static int eval(mpf_srcptr f) { return mpf_sgn(f); } +}; + +struct __gmp_gcd_function +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { + mpz_gcd(z, w, v); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + mpz_gcd_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + eval(z, w, __gmpxx_abs_ui(l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { + __GMPXX_TMPZ_D; mpz_gcd(z, w, temp); + } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { + eval(z, w, d); + } +}; + +struct __gmp_lcm_function +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { + mpz_lcm(z, w, v); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + mpz_lcm_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + eval(z, w, __gmpxx_abs_ui(l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { + __GMPXX_TMPZ_D; mpz_lcm(z, w, temp); + } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { + eval(z, w, d); + } +}; + +struct __gmp_cmp_function +{ + static int eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w); } + + static int eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l); } + static int eval(mpir_ui l, mpz_srcptr z) + { return -mpz_cmp_ui(z, l); } + static int eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l); } + static int eval(mpir_si l, mpz_srcptr z) + { return -mpz_cmp_si(z, l); } + static int eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d); } + static int eval(double d, mpz_srcptr z) + { return -mpz_cmp_d(z, d); } + + static int eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r); } + + static int eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1); } + static int eval(mpir_ui l, mpq_srcptr q) + { return -mpq_cmp_ui(q, l, 1); } + static int eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1); } + static int eval(mpir_si l, mpq_srcptr q) + { return -mpq_cmp_si(q, l, 1); } + static int eval(mpq_srcptr q, double d) + { + int i; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + i = mpq_cmp(q, temp); + mpq_clear(temp); + return i; + } + static int eval(double d, mpq_srcptr q) + { + int i; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + i = mpq_cmp(temp, q); + mpq_clear(temp); + return i; + } + + static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); } + + static int eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l); } + static int eval(mpir_ui l, mpf_srcptr f) + { return -mpf_cmp_ui(f, l); } + static int eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l); } + static int eval(mpir_si l, mpf_srcptr f) + { return -mpf_cmp_si(f, l); } + static int eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d); } + static int eval(double d, mpf_srcptr f) + { return -mpf_cmp_d(f, d); } +}; + +struct __gmp_rand_function +{ + static void eval(mpz_ptr z, gmp_randstate_t s, mp_bitcnt_t l) + { mpz_urandomb(z, s, l); } + static void eval(mpz_ptr z, gmp_randstate_t s, mpz_srcptr w) + { mpz_urandomm(z, s, w); } + static void eval(mpf_ptr f, gmp_randstate_t s, mp_bitcnt_t prec) + { mpf_urandomb(f, s, prec); } +}; + + +/**************** Auxiliary classes ****************/ + +/* this is much the same as gmp_allocated_string in gmp-impl.h + since gmp-impl.h is not publicly available, I redefine it here + I use a different name to avoid possible clashes */ + +extern "C" { + typedef void (*__gmp_freefunc_t) (void *, size_t); +} +struct __gmp_alloc_cstring +{ + char *str; + __gmp_alloc_cstring(char *s) { str = s; } + ~__gmp_alloc_cstring() + { + __gmp_freefunc_t freefunc; + mp_get_memory_functions (NULL, NULL, &freefunc); + (*freefunc) (str, std::strlen(str)+1); + } +}; + + +// general expression template class +template +class __gmp_expr; + + +// templates for resolving expression types +template +struct __gmp_resolve_ref +{ + typedef T ref_type; +}; + +template +struct __gmp_resolve_ref<__gmp_expr > +{ + typedef const __gmp_expr & ref_type; +}; + + +template +struct __gmp_resolve_expr; + +template <> +struct __gmp_resolve_expr +{ + typedef mpz_t value_type; + typedef mpz_ptr ptr_type; + typedef mpz_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; + typedef mpq_ptr ptr_type; + typedef mpq_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; + typedef mpf_ptr ptr_type; + typedef mpf_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) +namespace std { + template + struct common_type <__gmp_expr, __gmp_expr > + { + private: + typedef typename __gmp_resolve_expr::value_type X; + public: + typedef __gmp_expr type; + }; + + template + struct common_type <__gmp_expr, __gmp_expr > + { + typedef __gmp_expr type; + }; + +#define __GMPXX_DECLARE_COMMON_TYPE(typ) \ + template \ + struct common_type <__gmp_expr, typ > \ + { \ + typedef __gmp_expr type; \ + }; \ + \ + template \ + struct common_type > \ + { \ + typedef __gmp_expr type; \ + } + + __GMPXX_DECLARE_COMMON_TYPE(signed char); + __GMPXX_DECLARE_COMMON_TYPE(unsigned char); + __GMPXX_DECLARE_COMMON_TYPE(signed int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned int); + __GMPXX_DECLARE_COMMON_TYPE(signed short int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned short int); + __GMPXX_DECLARE_COMMON_TYPE(signed long int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned long int); + __GMPXX_DECLARE_COMMON_TYPE(float); + __GMPXX_DECLARE_COMMON_TYPE(double); +#undef __GMPXX_DECLARE_COMMON_TYPE +} +#endif + +// classes for evaluating unary and binary expressions +template +struct __gmp_unary_expr +{ + const T &val; + + __gmp_unary_expr(const T &v) : val(v) { } +private: + __gmp_unary_expr(); +}; + +template +struct __gmp_binary_expr +{ + typename __gmp_resolve_ref::ref_type val1; + typename __gmp_resolve_ref::ref_type val2; + + __gmp_binary_expr(const T &v1, const U &v2) : val1(v1), val2(v2) { } +private: + __gmp_binary_expr(); +}; + + + +/**************** Macros for in-class declarations ****************/ +/* This is just repetitive code that is easier to maintain if it's written + only once */ + +#define __GMPP_DECLARE_COMPOUND_OPERATOR(fun) \ + template \ + __gmp_expr & fun(const __gmp_expr &); +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DECLARE_COMPOUND_OPERATOR(fun) \ + __gmp_expr & fun(signed char); \ + __gmp_expr & fun(unsigned char); \ + __gmp_expr & fun(signed int); \ + __gmp_expr & fun(unsigned int); \ + __gmp_expr & fun(signed short int); \ + __gmp_expr & fun(unsigned short int); \ + __gmp_expr & fun(signed long int); \ + __gmp_expr & fun(unsigned long int); \ + __gmp_expr & fun(signed long long int); \ + __gmp_expr & fun(unsigned long long int); \ + __gmp_expr & fun(float); \ + __gmp_expr & fun(double); \ + __gmp_expr & fun(long double); +#else +#define __GMPN_DECLARE_COMPOUND_OPERATOR(fun) \ + __gmp_expr & fun(signed char); \ + __gmp_expr & fun(unsigned char); \ + __gmp_expr & fun(signed int); \ + __gmp_expr & fun(unsigned int); \ + __gmp_expr & fun(signed short int); \ + __gmp_expr & fun(unsigned short int); \ + __gmp_expr & fun(signed long int); \ + __gmp_expr & fun(unsigned long int); \ + __gmp_expr & fun(float); \ + __gmp_expr & fun(double); \ + __gmp_expr & fun(long double); +#endif + +#define __GMP_DECLARE_COMPOUND_OPERATOR(fun) \ +__GMPP_DECLARE_COMPOUND_OPERATOR(fun) \ +__GMPN_DECLARE_COMPOUND_OPERATOR(fun) + +#define __GMP_DECLARE_COMPOUND_OPERATOR_UI(fun) \ + __gmp_expr & fun(mp_bitcnt_t); + +#define __GMP_DECLARE_INCREMENT_OPERATOR(fun) \ + inline __gmp_expr & fun(); \ + inline __gmp_expr fun(int); + + +/**************** mpz_class -- wrapper for mpz_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpz_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } + + // constructors and destructor + __gmp_expr() { mpz_init(mp); } + + __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&z) + { *mp = *z.mp; mpz_init(z.mp); } +#endif + template + __gmp_expr(const __gmp_expr &expr) + { mpz_init(mp); __gmp_set_expr(mp, expr); } + template + explicit __gmp_expr(const __gmp_expr &expr) + { mpz_init(mp); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpz_init_set_si(mp, c); } + __gmp_expr(unsigned char c) { mpz_init_set_ui(mp, c); } + + __gmp_expr(signed int i) { mpz_init_set_si(mp, i); } + __gmp_expr(unsigned int i) { mpz_init_set_ui(mp, i); } + + __gmp_expr(signed short int s) { mpz_init_set_si(mp, s); } + __gmp_expr(unsigned short int s) { mpz_init_set_ui(mp, s); } + + __gmp_expr(signed long int l) { mpz_init_set_si(mp, l); } + __gmp_expr(unsigned long int l) { mpz_init_set_ui(mp, l); } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int l) { mpz_init_set_si(mp, l); } + __gmp_expr(unsigned long long int l) { mpz_init_set_ui(mp, l); } +#endif + +#ifdef MPIRXX_INTMAX_T + __gmp_expr(intmax_t l) { mpz_init_set_sx(mp, l); } +#endif + +#ifdef MPIRXX_UINTMAX_T + __gmp_expr(uintmax_t l) { mpz_init_set_ux(mp, l); } +#endif + + __gmp_expr(float f) { mpz_init_set_d(mp, f); } + __gmp_expr(double d) { mpz_init_set_d(mp, d); } + // __gmp_expr(long double ld) { mpz_init_set_d(mp, ld); } + + explicit __gmp_expr(const char *s, int base = 0) + { + if (mpz_init_set_str (mp, s, base) != 0) + { + mpz_clear (mp); + throw std::invalid_argument ("mpz_set_str"); + } + } + explicit __gmp_expr(const std::string &s, int base = 0) + { + if (mpz_init_set_str(mp, s.c_str(), base) != 0) + { + mpz_clear (mp); + throw std::invalid_argument ("mpz_set_str"); + } + } + + explicit __gmp_expr(mpz_srcptr z) { mpz_init_set(mp, z); } + + ~__gmp_expr() { mpz_clear(mp); } + + void swap(__gmp_expr& z) __GMPXX_NOEXCEPT { std::swap(*mp, *z.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &z) + { mpz_set(mp, z.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&z) __GMPXX_NOEXCEPT + { swap(z); return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + +__gmp_expr & operator=(signed char c) { mpz_set_si(mp, c); return *this; } +__gmp_expr & operator=(unsigned char c) { mpz_set_ui(mp, c); return *this; } + +__gmp_expr & operator=(signed int i) { mpz_set_si(mp, i); return *this; } +__gmp_expr & operator=(unsigned int i) { mpz_set_ui(mp, i); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpz_set_si(mp, s); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpz_set_ui(mp, s); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpz_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpz_set_ui(mp, l); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int i) { mpz_set_si(mp, i); return *this; } + __gmp_expr & operator=(unsigned long long int i) { mpz_set_ui(mp, i); return *this; } +#endif + +#ifdef MPIRXX_INTMAX_T + __gmp_expr & operator=(intmax_t i) { mpz_set_sx(mp, i); return *this; } +#endif + +#ifdef MPIRXX_UINTMAX_T + __gmp_expr & operator=(uintmax_t i) { mpz_set_ux(mp, i); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpz_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpz_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpz_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpz_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpz_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpz_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpz_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpz_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpz_set_str(mp, s.c_str(), base); } + std::string get_str(int base = 10) const + { + __gmp_alloc_cstring temp(mpz_get_str(0, base, mp)); + return std::string(temp.str); + } + + // conversion functions + mpz_srcptr __get_mp() const { return mp; } + mpz_ptr __get_mp() { return mp; } + mpz_srcptr get_mpz_t() const { return mp; } + mpz_ptr get_mpz_t() { return mp; } + + mpir_si get_si() const { return mpz_get_si(mp); } + mpir_ui get_ui() const { return mpz_get_ui(mp); } + +#ifdef MPIRXX_INTMAX_T + intmax_t get_sx() const { return mpz_get_sx(mp); } +#endif +#ifdef MPIRXX_UINTMAX_T + uintmax_t get_ux() const { return mpz_get_ux(mp); } +#endif + + double get_d() const { return mpz_get_d(mp); } + + // bool fits_schar_p() const { return mpz_fits_schar_p(mp); } + // bool fits_uchar_p() const { return mpz_fits_uchar_p(mp); } + bool fits_sint_p() const { return mpz_fits_sint_p(mp) != 0; } + bool fits_uint_p() const { return mpz_fits_uint_p(mp) != 0; } + bool fits_si_p() const { return mpz_fits_si_p(mp) != 0; } + bool fits_ui_p() const { return mpz_fits_ui_p(mp) != 0; } + bool fits_sshort_p() const { return mpz_fits_sshort_p(mp) != 0; } + bool fits_ushort_p() const { return mpz_fits_ushort_p(mp) != 0; } + bool fits_slong_p() const { return mpz_fits_slong_p(mp) != 0; } + bool fits_ulong_p() const { return mpz_fits_ulong_p(mp) != 0; } + // bool fits_float_p() const { return mpz_fits_float_p(mp) != 0; } + // bool fits_double_p() const { return mpz_fits_double_p(mp) != 0; } + // bool fits_ldouble_p() const { return mpz_fits_ldouble_p(mp) != 0; } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mp->_mp_size != 0; } +#endif + + // member operators + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator%=) + + __GMP_DECLARE_COMPOUND_OPERATOR(operator&=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator|=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator^=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpz_class; + + +/**************** mpq_class -- wrapper for mpq_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpq_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } + void canonicalize() { mpq_canonicalize(mp); } + + // constructors and destructor + __gmp_expr() { mpq_init(mp); } + + __gmp_expr(const __gmp_expr &q) + { + mpz_init_set(mpq_numref(mp), mpq_numref(q.mp)); + mpz_init_set(mpq_denref(mp), mpq_denref(q.mp)); + } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&q) + { *mp = *q.mp; mpq_init(q.mp); } +#endif + template + __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + template + __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + template + explicit __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpq_init(mp); mpq_set_si(mp, c, 1); } + __gmp_expr(unsigned char c) { mpq_init(mp); mpq_set_ui(mp, c, 1); } + + __gmp_expr(signed int i) { mpq_init(mp); mpq_set_si(mp, i, 1); } + __gmp_expr(unsigned int i) { mpq_init(mp); mpq_set_ui(mp, i, 1); } + + __gmp_expr(signed short int s) { mpq_init(mp); mpq_set_si(mp, s, 1); } + __gmp_expr(unsigned short int s) { mpq_init(mp); mpq_set_ui(mp, s, 1); } + + __gmp_expr(signed long int l) { mpq_init(mp); mpq_set_si(mp, l, 1); } + __gmp_expr(unsigned long int l) { mpq_init(mp); mpq_set_ui(mp, l, 1); } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int l) { mpq_init(mp); mpq_set_si(mp, l, 1); } + __gmp_expr(unsigned long long int l) { mpq_init(mp); mpq_set_ui(mp, l, 1); } +#endif + + __gmp_expr(float f) { mpq_init(mp); mpq_set_d(mp, f); } + __gmp_expr(double d) { mpq_init(mp); mpq_set_d(mp, d); } + // __gmp_expr(long double ld) { mpq_init(mp); mpq_set_ld(mp, ld); } + + explicit __gmp_expr(const char *s, int base = 0) + { + mpq_init (mp); + // If s is the literal 0, we meant to call another constructor. + // If s just happens to evaluate to 0, we would crash, so whatever. + if (s == 0) + { + // Don't turn mpq_class(0,0) into 0 + mpz_set_si(mpq_denref(mp), base); + } + else if (mpq_set_str(mp, s, base) != 0) + { + mpq_clear (mp); + throw std::invalid_argument ("mpq_set_str"); + } + } + explicit __gmp_expr(const std::string &s, int base = 0) + { + mpq_init(mp); + if (mpq_set_str (mp, s.c_str(), base) != 0) + { + mpq_clear (mp); + throw std::invalid_argument ("mpq_set_str"); + } + } + explicit __gmp_expr(mpq_srcptr q) + { + mpz_init_set(mpq_numref(mp), mpq_numref(q)); + mpz_init_set(mpq_denref(mp), mpq_denref(q)); + } + + __gmp_expr(const mpz_class &num, const mpz_class &den) + { + mpz_init_set(mpq_numref(mp), num.get_mpz_t()); + mpz_init_set(mpq_denref(mp), den.get_mpz_t()); + } + + ~__gmp_expr() { mpq_clear(mp); } + + void swap(__gmp_expr& q) __GMPXX_NOEXCEPT { std::swap(*mp, *q.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &q) + { mpq_set(mp, q.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&q) __GMPXX_NOEXCEPT + { swap(q); return *this; } + __gmp_expr & operator=(mpz_class &&z)__GMPXX_NOEXCEPT + { get_num() = std::move(z); get_den() = 1u; return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + + __gmp_expr & operator=(signed char c) + { mpq_set_si(mp, c, 1); return *this; } + __gmp_expr & operator=(unsigned char c) + { mpq_set_ui(mp, c, 1); return *this; } + + __gmp_expr & operator=(signed int i) { mpq_set_si(mp, i, 1); return *this; } + __gmp_expr & operator=(unsigned int i) + { mpq_set_ui(mp, i, 1); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpq_set_si(mp, s, 1); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpq_set_ui(mp, s, 1); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpq_set_si(mp, l, 1); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpq_set_ui(mp, l, 1); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int l) + { mpq_set_si(mp, l, 1); return *this; } + __gmp_expr & operator=(unsigned long long int l) + { mpq_set_ui(mp, l, 1); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpq_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpq_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpq_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpq_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpq_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpq_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpq_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpq_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpq_set_str(mp, s.c_str(), base); } + std::string get_str(int base = 10) const + { + __gmp_alloc_cstring temp(mpq_get_str(0, base, mp)); + return std::string(temp.str); + } + + // conversion functions + + // casting a reference to an mpz_t to mpz_class & is a dirty hack, + // but works because the internal representation of mpz_class is + // exactly an mpz_t + const mpz_class & get_num() const + { return reinterpret_cast(*mpq_numref(mp)); } + mpz_class & get_num() + { return reinterpret_cast(*mpq_numref(mp)); } + const mpz_class & get_den() const + { return reinterpret_cast(*mpq_denref(mp)); } + mpz_class & get_den() + { return reinterpret_cast(*mpq_denref(mp)); } + + mpq_srcptr __get_mp() const { return mp; } + mpq_ptr __get_mp() { return mp; } + mpq_srcptr get_mpq_t() const { return mp; } + mpq_ptr get_mpq_t() { return mp; } + + mpz_srcptr get_num_mpz_t() const { return mpq_numref(mp); } + mpz_ptr get_num_mpz_t() { return mpq_numref(mp); } + mpz_srcptr get_den_mpz_t() const { return mpq_denref(mp); } + mpz_ptr get_den_mpz_t() { return mpq_denref(mp); } + + double get_d() const { return mpq_get_d(mp); } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mpq_numref(mp)->_mp_size != 0; } +#endif + + // compound assignments + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpq_class; + + +/**************** mpf_class -- wrapper for mpf_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpf_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_prec(mp); } + + void set_prec(mp_bitcnt_t prec) { mpf_set_prec(mp, prec); } + void set_prec_raw(mp_bitcnt_t prec) { mpf_set_prec_raw(mp, prec); } + + // constructors and destructor + __gmp_expr() { mpf_init(mp); } + + __gmp_expr(const __gmp_expr &f) + { mpf_init2(mp, f.get_prec()); mpf_set(mp, f.mp); } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&f) + { *mp = *f.mp; mpf_init2(f.mp, get_prec()); } +#endif + __gmp_expr(const __gmp_expr &f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set(mp, f.mp); } + template + __gmp_expr(const __gmp_expr &expr) + { mpf_init2(mp, expr.get_prec()); __gmp_set_expr(mp, expr); } + template + __gmp_expr(const __gmp_expr &expr, mp_bitcnt_t prec) + { mpf_init2(mp, prec); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpf_init_set_si(mp, c); } + __gmp_expr(signed char c, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, c); } + __gmp_expr(unsigned char c) { mpf_init_set_ui(mp, c); } + __gmp_expr(unsigned char c, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, c); } + + __gmp_expr(signed int i) { mpf_init_set_si(mp, i); } + __gmp_expr(signed int i, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, i); } + __gmp_expr(unsigned int i) { mpf_init_set_ui(mp, i); } + __gmp_expr(unsigned int i, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, i); } + + __gmp_expr(signed short int s) { mpf_init_set_si(mp, s); } + __gmp_expr(signed short int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, s); } + __gmp_expr(unsigned short int s) { mpf_init_set_ui(mp, s); } + __gmp_expr(unsigned short int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, s); } + + __gmp_expr(signed long int l) { mpf_init_set_si(mp, l); } + __gmp_expr(signed long int l, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, l); } + __gmp_expr(unsigned long int l) { mpf_init_set_ui(mp, l); } + __gmp_expr(unsigned long int l, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, l); } +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int s) { mpf_init_set_si(mp, s); } + __gmp_expr(signed long long int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, s); } + __gmp_expr(unsigned long long int s) { mpf_init_set_ui(mp, s); } + __gmp_expr(unsigned long long int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, s); } +#endif + + __gmp_expr(float f) { mpf_init_set_d(mp, f); } + __gmp_expr(float f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_d(mp, f); } + __gmp_expr(double d) { mpf_init_set_d(mp, d); } + __gmp_expr(double d, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_d(mp, d); } + // __gmp_expr(long double ld) { mpf_init_set_d(mp, ld); } + // __gmp_expr(long double ld, mp_bitcnt_t prec) + // { mpf_init2(mp, prec); mpf_set_d(mp, ld); } + + explicit __gmp_expr(const char *s) + { + if (mpf_init_set_str (mp, s, 0) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + __gmp_expr(const char *s, mp_bitcnt_t prec, int base = 0) + { + mpf_init2(mp, prec); + if (mpf_set_str(mp, s, base) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + explicit __gmp_expr(const std::string &s) + { + if (mpf_init_set_str(mp, s.c_str(), 0) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + __gmp_expr(const std::string &s, mp_bitcnt_t prec, int base = 0) + { + mpf_init2(mp, prec); + if (mpf_set_str(mp, s.c_str(), base) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + + explicit __gmp_expr(mpf_srcptr f) + { mpf_init2(mp, mpf_get_prec(f)); mpf_set(mp, f); } + __gmp_expr(mpf_srcptr f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set(mp, f); } + + ~__gmp_expr() { mpf_clear(mp); } + + void swap(__gmp_expr& f) __GMPXX_NOEXCEPT { std::swap(*mp, *f.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &f) + { mpf_set(mp, f.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&f) __GMPXX_NOEXCEPT + { swap(f); return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + + __gmp_expr & operator=(signed char c) { mpf_set_si(mp, c); return *this; } + __gmp_expr & operator=(unsigned char c) { mpf_set_ui(mp, c); return *this; } + + __gmp_expr & operator=(signed int i) { mpf_set_si(mp, i); return *this; } + __gmp_expr & operator=(unsigned int i) { mpf_set_ui(mp, i); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpf_set_si(mp, s); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpf_set_ui(mp, s); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpf_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpf_set_ui(mp, l); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int l) + { mpf_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long long int l) + { mpf_set_ui(mp, l); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpf_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpf_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpf_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpf_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpf_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpf_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpf_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpf_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpf_set_str(mp, s.c_str(), base); } + std::string get_str(mp_exp_t &expo, int base = 10, size_t size = 0) const + { + __gmp_alloc_cstring temp(mpf_get_str(0, &expo, base, size, mp)); + return std::string(temp.str); + } + + // conversion functions + mpf_srcptr __get_mp() const { return mp; } + mpf_ptr __get_mp() { return mp; } + mpf_srcptr get_mpf_t() const { return mp; } + mpf_ptr get_mpf_t() { return mp; } + + mpir_si get_si() const { return mpf_get_si(mp); } + mpir_ui get_ui() const { return mpf_get_ui(mp); } + double get_d() const { return mpf_get_d(mp); } + + // bool fits_schar_p() const { return mpf_fits_schar_p(mp)!= 0; } + // bool fits_uchar_p() const { return mpf_fits_uchar_p(mp)!= 0; } + bool fits_sint_p() const { return mpf_fits_sint_p(mp) != 0; } + bool fits_uint_p() const { return mpf_fits_uint_p(mp) != 0; } + bool fits_si_p() const { return mpf_fits_si_p(mp) != 0; } + bool fits_ui_p() const { return mpf_fits_ui_p(mp) != 0; } + bool fits_sshort_p() const { return mpf_fits_sshort_p(mp) != 0; } + bool fits_ushort_p() const { return mpf_fits_ushort_p(mp) != 0; } + bool fits_slong_p() const { return mpf_fits_slong_p(mp) != 0; } + bool fits_ulong_p() const { return mpf_fits_ulong_p(mp) != 0; } + // bool fits_float_p() const { return mpf_fits_float_p(mp)!= 0; } + // bool fits_double_p() const { return mpf_fits_double_p(mp)!= 0; } + // bool fits_ldouble_p() const { return mpf_fits_ldouble_p(mp)!= 0; } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mp->_mp_size != 0; } +#endif + + // compound assignments + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpf_class; + + + +/**************** User-defined literals ****************/ + +#if __GMPXX_USE_CXX11 +inline mpz_class operator"" _mpz(const char* s) +{ + return mpz_class(s); +} + +inline mpq_class operator"" _mpq(const char* s) +{ + mpq_class q; + q.get_num() = s; + return q; +} + +inline mpf_class operator"" _mpf(const char* s) +{ + return mpf_class(s); +} +#endif + +/**************** I/O operators ****************/ + +// these should (and will) be provided separately + +template +inline std::ostream & operator<< +(std::ostream &o, const __gmp_expr &expr) +{ + __gmp_expr const& temp(expr); + return o << temp.__get_mp(); +} + +template +inline std::istream & operator>>(std::istream &i, __gmp_expr &expr) +{ + return i >> expr.__get_mp(); +} + +/* +// you might want to uncomment this +inline std::istream & operator>>(std::istream &i, mpq_class &q) +{ + i >> q.get_mpq_t(); + q.canonicalize(); + return i; +} +*/ + + +/**************** Functions for type conversion ****************/ + +inline void __gmp_set_expr(mpz_ptr z, const mpz_class &w) +{ + mpz_set(z, w.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + expr.eval(z); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + mpq_class const& temp(expr); + mpz_set_q(z, temp.get_mpq_t()); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + mpf_class const& temp(expr); + mpz_set_f(z, temp.get_mpf_t()); +} + +inline void __gmp_set_expr(mpq_ptr q, const mpz_class &z) +{ + mpq_set_z(q, z.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + __gmp_set_expr(mpq_numref(q), expr); + mpz_set_ui(mpq_denref(q), 1); +} + +inline void __gmp_set_expr(mpq_ptr q, const mpq_class &r) +{ + mpq_set(q, r.get_mpq_t()); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + expr.eval(q); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + mpf_class const& temp(expr); + mpq_set_f(q, temp.get_mpf_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + mpz_class const& temp(expr); + mpf_set_z(f, temp.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + mpq_class const& temp(expr); + mpf_set_q(f, temp.get_mpq_t()); +} + +inline void __gmp_set_expr(mpf_ptr f, const mpf_class &g) +{ + mpf_set(f, g.get_mpf_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + expr.eval(f); +} + + +/* Temporary objects */ + +template +class __gmp_temp +{ + __gmp_expr val; + public: + template + __gmp_temp(U const& u, V) : val (u) {} + typename __gmp_resolve_expr::srcptr_type + __get_mp() const { return val.__get_mp(); } +}; + +template <> +class __gmp_temp +{ + mpf_class val; + public: + template + __gmp_temp(U const& u, mpf_ptr res) : val (u, mpf_get_prec(res)) {} + mpf_srcptr __get_mp() const { return val.__get_mp(); } +}; + +/**************** Specializations of __gmp_expr ****************/ +/* The eval() method of __gmp_expr evaluates the corresponding + expression and assigns the result to its argument, which is either an + mpz_t, mpq_t, or mpf_t as specified by the T argument. + Compound expressions are evaluated recursively (temporaries are created + to hold intermediate values), while for simple expressions the eval() + method of the appropriate function object (available as the Op argument + of either __gmp_unary_expr or __gmp_binary_expr) is + called. */ + + +/**************** Unary expressions ****************/ +/* cases: + - simple: argument is mp*_class, that is, __gmp_expr + - compound: argument is __gmp_expr (with U not equal to T) */ + + +// simple expressions + +template +class __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val_type; + + __gmp_unary_expr expr; +public: + explicit __gmp_expr(const val_type &val) : expr(val) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val.__get_mp()); } + const val_type & get_val() const { return expr.val; } + mp_bitcnt_t get_prec() const { return expr.val.get_prec(); } +}; + + +// compound expressions + +template +class __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val_type; + + __gmp_unary_expr expr; +public: + explicit __gmp_expr(const val_type &val) : expr(val) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { expr.val.eval(p); Op::eval(p, p); } + const val_type & get_val() const { return expr.val; } + mp_bitcnt_t get_prec() const { return expr.val.get_prec(); } +}; + + +/**************** Binary expressions ****************/ +/* simple: + - arguments are both mp*_class + - one argument is mp*_class, one is a built-in type + compound: + - one is mp*_class, one is __gmp_expr + - one is __gmp_expr, one is built-in + - both arguments are __gmp_expr<...> */ + + +// simple expressions + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1.__get_mp(), expr.val2.__get_mp()); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +// simple expressions, T is a built-in numerical type + +template +class __gmp_expr, U, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef U val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1.__get_mp(), expr.val2); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val1.get_prec(); } +}; + +template +class __gmp_expr, Op> > +{ +private: + typedef U val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1, expr.val2.__get_mp()); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val2.get_prec(); } +}; + + +// compound expressions, one argument is a subexpression + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val1.__get_mp()) + { + __gmp_set_expr(p, expr.val2); + Op::eval(p, expr.val1.__get_mp(), p); + } + else + { + __gmp_temp temp(expr.val2, p); + Op::eval(p, expr.val1.__get_mp(), temp.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val2.__get_mp()) + { + __gmp_set_expr(p, expr.val1); + Op::eval(p, p, expr.val2.__get_mp()); + } + else + { + __gmp_temp temp(expr.val1, p); + Op::eval(p, temp.__get_mp(), expr.val2.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val1.__get_mp()) + { + __gmp_set_expr(p, expr.val2); + Op::eval(p, expr.val1.__get_mp(), p); + } + else + { + __gmp_temp temp(expr.val2, p); + Op::eval(p, expr.val1.__get_mp(), temp.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val2.__get_mp()) + { + __gmp_set_expr(p, expr.val1); + Op::eval(p, p, expr.val2.__get_mp()); + } + else + { + __gmp_temp temp(expr.val1, p); + Op::eval(p, temp.__get_mp(), expr.val2.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +// one argument is a subexpression, one is a built-in + +template +class __gmp_expr, V, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef V val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + expr.val1.eval(p); + Op::eval(p, p, expr.val2); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val1.get_prec(); } +}; + +template +class __gmp_expr, Op> > +{ +private: + typedef U val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + expr.val2.eval(p); + Op::eval(p, expr.val1, p); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val2.get_prec(); } +}; + + +// both arguments are subexpressions + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp2(expr.val2, p); + expr.val1.eval(p); + Op::eval(p, p, temp2.__get_mp()); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp1(expr.val1, p); + expr.val2.eval(p); + Op::eval(p, temp1.__get_mp(), p); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp2(expr.val2, p); + expr.val1.eval(p); + Op::eval(p, p, temp2.__get_mp()); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +/**************** Special cases ****************/ + +/* Some operations (i.e., add and subtract) with mixed mpz/mpq arguments + can be done directly without first converting the mpz to mpq. + Appropriate specializations of __gmp_expr are required. */ + + +#define __GMPZQ_DEFINE_EXPR(eval_fun) \ + \ +template <> \ +class __gmp_expr > \ +{ \ +private: \ + typedef mpz_class val1_type; \ + typedef mpq_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { eval_fun::eval(q, expr.val1.get_mpz_t(), expr.val2.get_mpq_t()); } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template <> \ +class __gmp_expr > \ +{ \ +private: \ + typedef mpq_class val1_type; \ + typedef mpz_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { eval_fun::eval(q, expr.val1.get_mpq_t(), expr.val2.get_mpz_t()); } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, eval_fun> > \ +{ \ +private: \ + typedef mpz_class val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpq_class temp(expr.val2); \ + eval_fun::eval(q, expr.val1.get_mpz_t(), temp.get_mpq_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, eval_fun> > \ +{ \ +private: \ + typedef mpq_class val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp(expr.val2); \ + eval_fun::eval(q, expr.val1.get_mpq_t(), temp.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, mpq_class, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef mpq_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp(expr.val1); \ + eval_fun::eval(q, temp.get_mpz_t(), expr.val2.get_mpq_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, mpz_class, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef mpz_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpq_class temp(expr.val1); \ + eval_fun::eval(q, temp.get_mpq_t(), expr.val2.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr, __gmp_expr, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp1(expr.val1); \ + expr.val2.eval(q); \ + eval_fun::eval(q, temp1.get_mpz_t(), q); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr, __gmp_expr, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp2(expr.val2); \ + expr.val1.eval(q); \ + eval_fun::eval(q, q, temp2.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; + + +__GMPZQ_DEFINE_EXPR(__gmp_binary_plus) +__GMPZQ_DEFINE_EXPR(__gmp_binary_minus) + + + +/**************** Macros for defining functions ****************/ +/* Results of operators and functions are instances of __gmp_expr. + T determines the numerical type of the expression: it can be either + mpz_t, mpq_t, or mpf_t. When the arguments of a binary + expression have different numerical types, __gmp_resolve_expr is used + to determine the "larger" type. + U is either __gmp_unary_expr or __gmp_binary_expr, + where V and W are the arguments' types -- they can in turn be + expressions, thus allowing to build compound expressions to any + degree of complexity. + Op is a function object that must have an eval() method accepting + appropriate arguments. + Actual evaluation of a __gmp_expr object is done when it gets + assigned to an mp*_class ("lazy" evaluation): this is done by calling + its eval() method. */ + + +// non-member unary operators and functions + +#define __GMP_DEFINE_UNARY_FUNCTION(fun, eval_fun) \ + \ +template \ +inline __gmp_expr, eval_fun> > \ +fun(const __gmp_expr &expr) \ +{ \ + return __gmp_expr, eval_fun> >(expr); \ +} + +#define __GMP_DEFINE_UNARY_TYPE_FUNCTION(type, fun, eval_fun) \ + \ +template \ +inline type fun(const __gmp_expr &expr) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(temp.__get_mp()); \ +} + + +// non-member binary operators and functions + +#define __GMPP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ + \ +template \ +inline __gmp_expr::value_type, \ +__gmp_binary_expr<__gmp_expr, __gmp_expr, eval_fun> > \ +fun(const __gmp_expr &expr1, const __gmp_expr &expr2) \ +{ \ + return __gmp_expr::value_type, \ + __gmp_binary_expr<__gmp_expr, __gmp_expr, eval_fun> > \ + (expr1, expr2); \ +} + +#define __GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, bigtype) \ + \ +template \ +inline __gmp_expr \ +, bigtype, eval_fun> > \ +fun(const __gmp_expr &expr, type t) \ +{ \ + return __gmp_expr \ + , bigtype, eval_fun> >(expr, t); \ +} \ + \ +template \ +inline __gmp_expr \ +, eval_fun> > \ +fun(type t, const __gmp_expr &expr) \ +{ \ + return __gmp_expr \ + , eval_fun> >(t, expr); \ +} + +#define __GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, mpir_si) + +#define __GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, mpir_ui) + +#define __GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, double) + +#define __GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, long double) +#else +#define __GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, long double) +#endif + +#define __GMP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) + + +#define __GMP_DEFINE_BINARY_FUNCTION_UI(fun, eval_fun) \ + \ +template \ +inline __gmp_expr \ +, mp_bitcnt_t, eval_fun> > \ +fun(const __gmp_expr &expr, mp_bitcnt_t l) \ +{ \ + return __gmp_expr, mpir_ui, eval_fun> >(expr, l); \ +} + + +#define __GMPP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ + \ +template \ +inline type fun(const __gmp_expr &expr1, \ + const __gmp_expr &expr2) \ +{ \ + typedef typename __gmp_resolve_expr::value_type eval_type; \ + __gmp_expr const& temp1(expr1); \ + __gmp_expr const& temp2(expr2); \ + return eval_fun::eval(temp1.__get_mp(), temp2.__get_mp()); \ +} + +#define __GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, bigtype) \ + \ +template \ +inline type fun(const __gmp_expr &expr, type2 t) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(temp.__get_mp(), static_cast(t)); \ +} \ + \ +template \ +inline type fun(type2 t, const __gmp_expr &expr) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(static_cast(t), temp.__get_mp()); \ +} + +#define __GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, mpir_si) + +#define __GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, mpir_ui) + +#define __GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2, double) + +#define __GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, long double) +#else +#define __GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, long double) +#endif + +#define __GMP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) + + +// member operators + +#define __GMPP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ + \ +template \ +inline type##_class & type##_class::fun(const __gmp_expr &expr) \ +{ \ + __gmp_set_expr(mp, __gmp_expr, eval_fun> >(*this, expr)); \ + return *this; \ +} + +#define __GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, bigtype) \ + \ +inline type##_class & type##_class::fun(type2 t) \ +{ \ + __gmp_set_expr(mp, __gmp_expr >(*this, t)); \ + return *this; \ +} + +#define __GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, mpir_si) + +#define __GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, mpir_ui) + +#define __GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2, double) + +#define __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, float) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, double) \ +/* __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, long double) */ +#else +#define __GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, float) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, double) \ +/* __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, long double) */ +#endif + +#define __GMP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) + +#define __GMPZ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpf, fun, eval_fun) + + + +#define __GMP_DEFINE_COMPOUND_OPERATOR_UI(type, fun, eval_fun) \ + \ +inline type##_class & type##_class::fun(mpir_ui l) \ +{ \ + __gmp_set_expr(mp, __gmp_expr >(*this, l)); \ + return *this; \ +} + +#define __GMPZ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpf, fun, eval_fun) + + + +#define __GMP_DEFINE_INCREMENT_OPERATOR(type, fun, eval_fun) \ + \ +inline type##_class & type##_class::fun() \ +{ \ + eval_fun::eval(mp); \ + return *this; \ +} \ + \ +inline type##_class type##_class::fun(int) \ +{ \ + type##_class temp(*this); \ + eval_fun::eval(mp); \ + return temp; \ +} + +#define __GMPZ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpf, fun, eval_fun) + + + +/**************** Arithmetic operators and functions ****************/ + +// non-member operators and functions + +__GMP_DEFINE_UNARY_FUNCTION(operator+, __gmp_unary_plus) +__GMP_DEFINE_UNARY_FUNCTION(operator-, __gmp_unary_minus) +__GMP_DEFINE_UNARY_FUNCTION(operator~, __gmp_unary_com) + +__GMP_DEFINE_BINARY_FUNCTION(operator+, __gmp_binary_plus) +__GMP_DEFINE_BINARY_FUNCTION(operator-, __gmp_binary_minus) +__GMP_DEFINE_BINARY_FUNCTION(operator*, __gmp_binary_multiplies) +__GMP_DEFINE_BINARY_FUNCTION(operator/, __gmp_binary_divides) +__GMP_DEFINE_BINARY_FUNCTION(operator%, __gmp_binary_modulus) +__GMP_DEFINE_BINARY_FUNCTION(operator&, __gmp_binary_and) +__GMP_DEFINE_BINARY_FUNCTION(operator|, __gmp_binary_ior) +__GMP_DEFINE_BINARY_FUNCTION(operator^, __gmp_binary_xor) + +__GMP_DEFINE_BINARY_FUNCTION_UI(operator<<, __gmp_binary_lshift) +__GMP_DEFINE_BINARY_FUNCTION_UI(operator>>, __gmp_binary_rshift) + +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator==, __gmp_binary_equal) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator!=, ! __gmp_binary_equal) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<, __gmp_binary_less) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<=, ! __gmp_binary_greater) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>, __gmp_binary_greater) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>=, ! __gmp_binary_less) + +__GMP_DEFINE_UNARY_FUNCTION(abs, __gmp_abs_function) +__GMP_DEFINE_UNARY_FUNCTION(trunc, __gmp_trunc_function) +__GMP_DEFINE_UNARY_FUNCTION(floor, __gmp_floor_function) +__GMP_DEFINE_UNARY_FUNCTION(ceil, __gmp_ceil_function) +__GMP_DEFINE_UNARY_FUNCTION(sqrt, __gmp_sqrt_function) +__GMP_DEFINE_BINARY_FUNCTION(hypot, __gmp_hypot_function) + +__GMP_DEFINE_UNARY_TYPE_FUNCTION(int, sgn, __gmp_sgn_function) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(int, cmp, __gmp_cmp_function) + +template +void swap(__gmp_expr& x, __gmp_expr& y) __GMPXX_NOEXCEPT +{ x.swap(y); } + +// member operators for mpz_class + +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator%=, __gmp_binary_modulus) + +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator&=, __gmp_binary_and) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator|=, __gmp_binary_ior) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator^=, __gmp_binary_xor) + +__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPZ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPZ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + +// member operators for mpq_class + +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) + +__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPQ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPQ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + +// member operators for mpf_class + +__GMPF_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) + +__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPF_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPF_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + + + +/**************** Class wrapper for gmp_randstate_t ****************/ + +class __gmp_urandomb_value { }; +class __gmp_urandomm_value { }; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mp_bitcnt_t bits; +public: + __gmp_expr(gmp_randstate_t s, mp_bitcnt_t l) : state(s), bits(l) { } + void eval(mpz_ptr z) const { __gmp_rand_function::eval(z, state, bits); } + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } +}; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mpz_class range; +public: + __gmp_expr(gmp_randstate_t s, const mpz_class &z) : state(s), range(z) { } + void eval(mpz_ptr z) const + { __gmp_rand_function::eval(z, state, range.get_mpz_t()); } + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } +}; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mp_bitcnt_t bits; +public: + __gmp_expr(gmp_randstate_t s, mp_bitcnt_t l) : state(s), bits(l) { } + void eval(mpf_ptr f) const + { + __gmp_rand_function::eval(f, state, + (bits>0) ? bits : mpf_get_prec(f)); + } + mp_bitcnt_t get_prec() const + { + if (bits == 0) + return mpf_get_default_prec(); + else + return bits; + } +}; + +extern "C" { + typedef void __gmp_randinit_default_t (gmp_randstate_t); + typedef void __gmp_randinit_lc_2exp_t (gmp_randstate_t, mpz_srcptr, mpir_ui, mp_bitcnt_t); + typedef int __gmp_randinit_lc_2exp_size_t (gmp_randstate_t, mp_bitcnt_t); +} + +class gmp_randclass +{ +private: + gmp_randstate_t state; + + // copy construction and assignment not allowed + gmp_randclass(const gmp_randclass &); + void operator=(const gmp_randclass &); +public: + // constructors and destructor + gmp_randclass(gmp_randalg_t alg, mp_bitcnt_t size) + { + switch (alg) + { + case GMP_RAND_ALG_LC: // no other cases for now + default: + gmp_randinit(state, alg, size); + break; + } + } + + // gmp_randinit_default + gmp_randclass(__gmp_randinit_default_t* f) { f(state); } + + // gmp_randinit_lc_2exp + gmp_randclass(__gmp_randinit_lc_2exp_t* f, + mpz_class z, mpir_ui l1, mp_bitcnt_t l2) + { f(state, z.get_mpz_t(), l1, l2); } + + // gmp_randinit_lc_2exp_size + gmp_randclass(__gmp_randinit_lc_2exp_size_t* f, + mp_bitcnt_t size) + { + if (f (state, size) == 0) + throw std::length_error ("gmp_randinit_lc_2exp_size"); + } + + ~gmp_randclass() { gmp_randclear(state); } + + // initialize + void seed(); // choose a random seed some way (?) + void seed(mpir_ui s) { gmp_randseed_ui(state, s); } + void seed(const mpz_class &z) { gmp_randseed(state, z.get_mpz_t()); } + + // get random number + __gmp_expr get_z_bits(mp_bitcnt_t l) + { return __gmp_expr(state, l); } + __gmp_expr get_z_bits(const mpz_class &z) + { return get_z_bits(z.get_ui()); } + // FIXME: z.get_bitcnt_t() ? + + __gmp_expr get_z_range(const mpz_class &z) + { return __gmp_expr(state, z); } + + __gmp_expr get_f(mp_bitcnt_t prec = 0) + { return __gmp_expr(state, prec); } +}; + + +/**************** Specialize std::numeric_limits ****************/ + +namespace std { + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpz_class min() { return mpz_class(); } + static mpz_class max() { return mpz_class(); } + static mpz_class lowest() { return mpz_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const int radix = 2; + static mpz_class epsilon() { return mpz_class(); } + static mpz_class round_error() { return mpz_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpz_class infinity() { return mpz_class(); } + static mpz_class quiet_NaN() { return mpz_class(); } + static mpz_class signaling_NaN() { return mpz_class(); } + static mpz_class denorm_min() { return mpz_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; + }; + + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpq_class min() { return mpq_class(); } + static mpq_class max() { return mpq_class(); } + static mpq_class lowest() { return mpq_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = true; + static const int radix = 2; + static mpq_class epsilon() { return mpq_class(); } + static mpq_class round_error() { return mpq_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpq_class infinity() { return mpq_class(); } + static mpq_class quiet_NaN() { return mpq_class(); } + static mpq_class signaling_NaN() { return mpq_class(); } + static mpq_class denorm_min() { return mpq_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; + }; + + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpf_class min() { return mpf_class(); } + static mpf_class max() { return mpf_class(); } + static mpf_class lowest() { return mpf_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = 2; + static mpf_class epsilon() { return mpf_class(); } + static mpf_class round_error() { return mpf_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpf_class infinity() { return mpf_class(); } + static mpf_class quiet_NaN() { return mpf_class(); } + static mpf_class signaling_NaN() { return mpf_class(); } + static mpf_class denorm_min() { return mpf_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + }; +} + + +/**************** #undef all private macros ****************/ + +#undef __GMPP_DECLARE_COMPOUND_OPERATOR +#undef __GMPN_DECLARE_COMPOUND_OPERATOR +#undef __GMP_DECLARE_COMPOUND_OPERATOR +#undef __GMP_DECLARE_COMPOUND_OPERATOR_UI +#undef __GMP_DECLARE_INCREMENT_OPERATOR + +#undef __GMPZQ_DEFINE_EXPR + +#undef __GMP_DEFINE_UNARY_FUNCTION +#undef __GMP_DEFINE_UNARY_TYPE_FUNCTION + +#undef __GMPP_DEFINE_BINARY_FUNCTION +#undef __GMPNN_DEFINE_BINARY_FUNCTION +#undef __GMPNS_DEFINE_BINARY_FUNCTION +#undef __GMPNU_DEFINE_BINARY_FUNCTION +#undef __GMPND_DEFINE_BINARY_FUNCTION +#undef __GMPNLD_DEFINE_BINARY_FUNCTION +#undef __GMPN_DEFINE_BINARY_FUNCTION +#undef __GMP_DEFINE_BINARY_FUNCTION + +#undef __GMP_DEFINE_BINARY_FUNCTION_UI + +#undef __GMPP_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNN_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNS_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNU_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPND_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNLD_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPN_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMP_DEFINE_BINARY_TYPE_FUNCTION + +#undef __GMPZ_DEFINE_COMPOUND_OPERATOR + +#undef __GMPP_DEFINE_COMPOUND_OPERATOR +#undef __GMPNN_DEFINE_COMPOUND_OPERATOR +#undef __GMPNS_DEFINE_COMPOUND_OPERATOR +#undef __GMPNU_DEFINE_COMPOUND_OPERATOR +#undef __GMPND_DEFINE_COMPOUND_OPERATOR +#undef __GMPNLD_DEFINE_COMPOUND_OPERATOR +#undef __GMPN_DEFINE_COMPOUND_OPERATOR +#undef __GMP_DEFINE_COMPOUND_OPERATOR + +#undef __GMPQ_DEFINE_COMPOUND_OPERATOR +#undef __GMPF_DEFINE_COMPOUND_OPERATOR + +#undef __GMP_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPZ_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPQ_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPF_DEFINE_COMPOUND_OPERATOR_UI + +#undef __GMP_DEFINE_INCREMENT_OPERATOR +#undef __GMPZ_DEFINE_INCREMENT_OPERATOR +#undef __GMPQ_DEFINE_INCREMENT_OPERATOR +#undef __GMPF_DEFINE_INCREMENT_OPERATOR + +#undef __GMPXX_CONSTANT + +#endif /* __GMP_PLUSPLUS__ */ diff --git a/include/mpir_x64-windows/include/mpir.h b/include/mpir_x64-windows/include/mpir.h new file mode 100644 index 0000000..a4ac54d --- /dev/null +++ b/include/mpir_x64-windows/include/mpir.h @@ -0,0 +1,1944 @@ +/* generated from gmp-h.in by gen_mpir_h.bat */ +/* Definitions for GNU multiple precision functions. -*- mode: c -*- +Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, +2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, +Inc. +Copyright 2008 William Hart, Gonzalo Tornaria +This file is part of the MPIR Library. +The MPIR Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. +The MPIR Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ +#ifndef __GMP_H__ +#ifdef __SUNPRO_CC /* See: http://trac.sagemath.org/sage_trac/ticket/7849 */ +#include /* This is Bill Hart's fix, but I've applied it only */ +#include /* on Sun Studio */ +#endif +#if defined (__cplusplus) +#include /* for size_t */ +#include /* for std::istream, std::ostream, std::string */ +#include +#endif +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#ifdef _WIN32 +# ifdef _WIN64 +# define _LONG_LONG_LIMB 1 +# define GMP_LIMB_BITS 64 +# else +# define GMP_LIMB_BITS 32 +# endif +# define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS +# define SIZEOF_MP_LIMB_T (GMP_LIMB_BITS >> 3) +# define GMP_NAIL_BITS 0 +#endif +#endif +#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) +#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS) +#define GMP_NUMB_MAX GMP_NUMB_MASK +#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) +#ifndef __GNU_MP__ +#define __GNU_MP__ 4 +#define __need_size_t /* tell gcc stddef.h we only want size_t */ +#if ! defined (__cplusplus) +#include /* for size_t */ +#endif +#undef __need_size_t +/* Instantiated by configure. */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#endif +/* #if defined(__GMP_WITHIN_CONFIGURE) && defined(_WIN64) */ +#ifdef __WIN64 +#define _LONG_LONG_LIMB 1 +#endif +/* __STDC__ - some ANSI compilers define this only to 0, hence the use of + "defined" and not "__STDC__-0". In particular Sun workshop C 5.0 + sets __STDC__ to 0, but requires "##" for token pasting. + _AIX - gnu ansidecl.h asserts that all known AIX compilers are ANSI but + don't always define __STDC__. + __DECC - current versions of DEC C (5.9 for instance) for alpha are ANSI, + but don't define __STDC__ in their default mode. Don't know if old + versions might have been K&R, but let's not worry about that unless + someone is still using one. + _mips - gnu ansidecl.h says the RISC/OS MIPS compiler is ANSI in SVR4 + mode, but doesn't define __STDC__. + _MSC_VER - Microsoft C is ANSI, but __STDC__ is undefined unless the /Za + option is given (in which case it's 1). + _WIN32 - tested for by gnu ansidecl.h, no doubt on the assumption that + all w32 compilers are ansi. + Note: This same set of tests is used by gen-psqr.c and + demos/expr/expr-impl.h, so if anything needs adding, then be sure to + update those too. */ +#if defined (__STDC__) \ + || defined (__cplusplus) \ + || defined (_AIX) \ + || defined (__DECC) \ + || (defined (__mips) && defined (_SYSTYPE_SVR4)) \ + || defined (_MSC_VER) \ + || defined (_WIN32) +#define __GMP_HAVE_CONST 1 +#define __GMP_HAVE_PROTOTYPES 1 +#define __GMP_HAVE_TOKEN_PASTE 1 +#else +#define __GMP_HAVE_CONST 0 +#define __GMP_HAVE_PROTOTYPES 0 +#define __GMP_HAVE_TOKEN_PASTE 0 +#endif +#if __GMP_HAVE_CONST +#define __gmp_const const +#define __gmp_signed signed +#else +#define __gmp_const +#define __gmp_signed +#endif +/* __GMP_DECLSPEC supports Windows DLL versions of libmpir, and is empty in + all other circumstances. + When compiling objects for libmpir, __GMP_DECLSPEC is an export directive, + or when compiling for an application it's an import directive. The two + cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles + (and not defined from an application). + __GMP_DECLSPEC_XX is similarly used for libmpirxx. __GMP_WITHIN_GMPXX + indicates when building libmpirxx, and in that case libmpirxx functions are + exports, but libmpir functions which might get called are imports. + libmp.la uses __GMP_DECLSPEC, just as if it were libmpir.la. libmpir and + libmp don't call each other, so there's no conflict or confusion. + Libtool DLL_EXPORT define is not used. + There's no attempt to support GMP built both static and DLL. Doing so + would mean applications would have to tell us which of the two is going + to be used when linking, and that seems very tedious and error prone if + using GMP by hand, and equally tedious from a package since autoconf and + automake don't give much help. + __GMP_DECLSPEC is required on all documented global functions and + variables, the various internals in gmp-impl.h etc can be left unadorned. + But internals used by the test programs or speed measuring programs + should have __GMP_DECLSPEC, and certainly constants or variables must + have it or the wrong address will be resolved. + In gcc __declspec can go at either the start or end of a prototype. + In Microsoft C __declspec must go at the start, or after the type like + void __declspec(...) *foo()". There's no __dllexport or anything to + guard against someone foolish #defining dllexport. _export used to be + available, but no longer. + In Borland C _export still exists, but needs to go after the type, like + "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to + make use of that. Probably more trouble than it's worth. */ +#if defined (__GNUC__) +#define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__) +#define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__) +#endif +#if defined (_MSC_VER) || defined (__BORLANDC__) +#define __GMP_DECLSPEC_EXPORT __declspec(dllexport) +#define __GMP_DECLSPEC_IMPORT __declspec(dllimport) +#endif +#ifdef __WATCOMC__ +#define __GMP_DECLSPEC_EXPORT __export +#define __GMP_DECLSPEC_IMPORT __import +#endif +#ifdef __IBMC__ +#define __GMP_DECLSPEC_EXPORT _Export +#define __GMP_DECLSPEC_IMPORT _Import +#endif +#if defined( _MSC_VER ) +# if defined( MSC_BUILD_DLL ) +# define __GMP_LIBGMP_DLL 1 +# define __GMP_WITHIN_GMP 1 +# define __GMP_WITHIN_GMPXX 1 +# elif defined( MSC_USE_DLL ) +# define __GMP_LIBGMP_DLL 1 +# endif +#endif +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMP +/* compiling to go into a DLL libmpir */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into an application which will link to a DLL libmpir */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC +#endif +#ifdef __GMP_SHORT_LIMB +typedef unsigned int mp_limb_t; +typedef int mp_limb_signed_t; +#else +#ifdef _LONG_LONG_LIMB +typedef unsigned long long int mp_limb_t; +typedef long long int mp_limb_signed_t; +#else +typedef unsigned long int mp_limb_t; +typedef long int mp_limb_signed_t; +#endif +#endif +#ifdef _WIN64 +#define BITS_PER_UI BITS_PER_MP_LIMB +typedef mp_limb_t mpir_ui; +typedef mp_limb_signed_t mpir_si; +typedef mpir_ui mp_bitcnt_t; +#else +#define BITS_PER_UI BITS_PER_ULONG +typedef unsigned long mpir_ui; +typedef long mpir_si; +typedef mpir_ui mp_bitcnt_t; +#endif +#define GMP_UI_MAX ((mpir_ui)(~(mpir_ui)0)) +#define GMP_UI_HIBIT (GMP_UI_MAX ^ (GMP_UI_MAX >> 1)) +#define GMP_SI_MAX ((mpir_si)(GMP_UI_MAX ^ GMP_UI_HIBIT)) +#define GMP_SI_MIN ((mpir_si)GMP_UI_HIBIT) +#define __GMP_BITCNT_MAX (~(mp_bitcnt_t)0) +/* For reference, note that the name __mpz_struct gets into C++ mangled + function names, which means although the "__" suggests an internal, we + must leave this name for binary compatibility. */ +typedef struct +{ + int _mp_alloc; /* Number of *limbs* allocated and pointed + to by the _mp_d field. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpz_struct; +#endif /* __GNU_MP__ */ +typedef __mpz_struct mpz_t[1]; +typedef mp_limb_t * mp_ptr; +typedef __gmp_const mp_limb_t * mp_srcptr; +#if defined( _WIN64) +#define __GMP_MP_SIZE_T_INT 0 +typedef long long int mp_size_t; +typedef long int mp_exp_t; +#else +#define __GMP_MP_SIZE_T_INT 0 +typedef long int mp_size_t; +typedef long int mp_exp_t; +#endif +typedef struct +{ + __mpz_struct _mp_num; + __mpz_struct _mp_den; +} __mpq_struct; +typedef __mpq_struct mpq_t[1]; +typedef struct +{ + int _mp_prec; /* Max precision, in number of `mp_limb_t's. + Set by mpf_init and modified by + mpf_set_prec. The area pointed to by the + _mp_d field contains `prec' + 1 limbs. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpf_struct; +typedef __mpf_struct mpf_t[1]; +/* Available random number generation algorithms. */ +typedef enum +{ + GMP_RAND_ALG_DEFAULT = 0, + GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ +} gmp_randalg_t; +/* Random state struct. */ +typedef struct +{ + mpz_t _mp_seed; /* _mp_d member points to state of the generator. */ + gmp_randalg_t _mp_alg; /* Currently unused. */ + union { + void *_mp_lc; /* Pointer to function pointers structure. */ + } _mp_algdata; +} __gmp_randstate_struct; +typedef __gmp_randstate_struct gmp_randstate_t[1]; +/* Types for function declarations in gmp files. */ +/* ??? Should not pollute user name space with these ??? */ +typedef __gmp_const __mpz_struct *mpz_srcptr; +typedef __mpz_struct *mpz_ptr; +typedef __gmp_const __mpf_struct *mpf_srcptr; +typedef __mpf_struct *mpf_ptr; +typedef __gmp_const __mpq_struct *mpq_srcptr; +typedef __mpq_struct *mpq_ptr; +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMPXX +/* compiling to go into a DLL libmpirxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into a application which will link to a DLL libmpirxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC_XX +#endif +#if __GMP_HAVE_PROTOTYPES +#define __GMP_PROTO(x) x +#else +#define __GMP_PROTO(x) () +#endif +#ifndef __MPN +#if __GMP_HAVE_TOKEN_PASTE +#define __MPN(x) __gmpn_##x +#else +#define __MPN(x) __gmpn_/**/x +#endif +#endif +/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, + defines EOF but not FILE. */ +#if defined (FILE) \ + || defined (H_STDIO) \ + || defined (_H_STDIO) /* AIX */ \ + || defined (_STDIO_H) /* glibc, Sun, SCO */ \ + || defined (_STDIO_H_) /* BSD, OSF */ \ + || defined (__STDIO_H) /* Borland */ \ + || defined (__STDIO_H__) /* IRIX */ \ + || defined (_STDIO_INCLUDED) /* HPUX */ \ + || defined (_FILE_DEFINED) /* Microsoft */ \ + || defined (__STDIO__) /* Apple MPW MrC */ \ + || defined (_MSL_STDIO_H) /* Metrowerks */ \ + || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ + || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ +#define _GMP_H_HAVE_FILE 1 +#endif +/* In ISO C, if a prototype involving "struct obstack *" is given without + that structure defined, then the struct is scoped down to just the + prototype, causing a conflict if it's subsequently defined for real. So + only give prototypes if we've got obstack.h. */ +#if defined (_OBSTACK_H) /* glibc */ +#define _GMP_H_HAVE_OBSTACK 1 +#endif +/* The prototypes for gmp_vprintf etc are provided only if va_list is + available, via an application having included or . + Usually va_list is a typedef so can't be tested directly, but C99 + specifies that va_start is a macro (and it was normally a macro on past + systems too), so look for that. + will define some sort of va_list for vprintf and vfprintf, but + let's not bother trying to use that since it's not standard and since + application uses for gmp_vprintf etc will almost certainly require the + whole or anyway. */ +#ifdef va_start +#define _GMP_H_HAVE_VA_LIST 1 +#endif +/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */ +#if defined (__GNUC__) && defined (__GNUC_MINOR__) +#define __GMP_GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GMP_GNUC_PREREQ(maj, min) 0 +#endif +/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically + it means a function does nothing but examine its arguments and memory + (global or via arguments) to generate a return value, but changes nothing + and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets + tune/common.c etc turn this off when trying to write timing loops. */ +#if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE) +#define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +#define __GMP_ATTRIBUTE_PURE +#endif +/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean + to "g++ -Wold-style-cast". + Casts in "extern inline" code within an extern "C" block don't induce + these warnings, so __GMP_CAST only needs to be used on documented + macros. */ +#ifdef __cplusplus +#define __GMP_CAST(type, expr) (static_cast (expr)) +#else +#define __GMP_CAST(type, expr) ((type) (expr)) +#endif +/* An empty "throw ()" means the function doesn't throw any C++ exceptions, + this can save some stack frame info in applications. + Currently it's given only on functions which never divide-by-zero etc, + don't allocate memory, and are expected to never need to allocate memory. + This leaves open the possibility of a C++ throw from a future GMP + exceptions scheme. + mpz_set_ui etc are omitted to leave open the lazy allocation scheme + described in doc/tasks.html. mpz_get_d etc are omitted to leave open + exceptions for float overflows. + Note that __GMP_NOTHROW must be given on any inlines the same as on their + prototypes (for g++ at least, where they're used together). Note also + that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like + __GMP_ATTRIBUTE_PURE. */ +#if defined (__cplusplus) +#define __GMP_NOTHROW throw () +#else +#define __GMP_NOTHROW +#endif +/* PORTME: What other compilers have a useful "extern inline"? "static + inline" would be an acceptable substitute if the compiler (or linker) + discards unused statics. */ +/* gcc has __inline__ in all modes, including strict ansi. Give a prototype + for an inline too, so as to correctly specify "dllimport" on windows, in + case the function is called rather than inlined. */ +#ifdef __GNUC__ +#if defined(__APPLE_CC__) && (__APPLE_CC__ != 1) /* FSF GCC sets this flag to 1 on Apple machines */ +#if ! (__APPLE_CC__ >= 5465 && __STDC_VERSION__ >= 199901L) +#define __GMP_EXTERN_INLINE extern __inline__ +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#else /*GNU CC*/ +#if defined(__GNUC_STDC_INLINE__) || defined (__GNUC_GNU_INLINE__) +#define __GMP_EXTERN_INLINE extern __inline__ __attribute__((__gnu_inline__)) +#else +#define __GMP_EXTERN_INLINE extern __inline__ +#endif +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#endif +/* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1 + strict ANSI mode. Inlining is done even when not optimizing (ie. -O0 + mode, which is the default), but an unnecessary local copy of foo is + emitted unless -O is used. "extern __inline" is accepted, but the + "extern" appears to be ignored, ie. it becomes a plain global function + but which is inlined within its file. Don't know if all old versions of + DEC C supported __inline, but as a start let's do the right thing for + current versions. */ +#ifdef __DECC +#define __GMP_EXTERN_INLINE static __inline +#endif +/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict + ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes + place under -O. Without -O "foo" seems to be emitted whether it's used + or not, which is wasteful. "extern inline foo()" isn't useful, the + "extern" is apparently ignored, so foo is inlined if possible but also + emitted as a global, which causes multiple definition errors when + building a shared libmpir. */ +#ifdef __SCO_VERSION__ +#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE static inline +#endif +#endif +#if defined _MSC_VER +#define __GMP_EXTERN_INLINE static __inline +#endif +/* C++ always has "inline" and since it's a normal feature the linker should + discard duplicate non-inlined copies, or if it doesn't then that's a + problem for everyone, not just GMP. */ +#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE inline +#endif +/* Don't do any inlining within a configure run, since if the compiler ends + up emitting copies of the code into the object file it can end up + demanding the various support routines (like mpn_popcount) for linking, + making the "alloca" test and perhaps others fail. And on hppa ia64 a + pre-release gcc 3.2 was seen not respecting the "extern" in "extern + __inline__", triggering this problem too. */ +#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE +#undef __GMP_EXTERN_INLINE +#endif +/* By default, don't give a prototype when there's going to be an inline + version. Note in particular that Cray C++ objects to the combination of + prototype and inline. */ +#ifdef __GMP_EXTERN_INLINE +#ifndef __GMP_INLINE_PROTOTYPES +#define __GMP_INLINE_PROTOTYPES 0 +#endif +#else +#define __GMP_INLINE_PROTOTYPES 1 +#endif +#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x)) +#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i)) +/* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted + to int by "~". */ +#define __GMP_UINT_MAX (~ (unsigned) 0) +#define __GMP_ULONG_MAX (~ (unsigned long) 0) +#define __GMP_USHRT_MAX ((unsigned short) ~0) +/* __builtin_expect is in gcc 3.0, and not in 2.95. */ +#if __GMP_GNUC_PREREQ (3,0) +#define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1) +#define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0) +#else +#define __GMP_LIKELY(cond) (cond) +#define __GMP_UNLIKELY(cond) (cond) +#endif +/* Allow direct user access to numerator and denominator of a mpq_t object. */ +#define mpq_numref(Q) (&((Q)->_mp_num)) +#define mpq_denref(Q) (&((Q)->_mp_den)) +#if defined (__cplusplus) +extern "C" { +using std::FILE; +#endif +#define mp_set_memory_functions __gmp_set_memory_functions +__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (size_t), + void *(*) (void *, size_t, size_t), + void (*) (void *, size_t))) __GMP_NOTHROW; +#define mp_get_memory_functions __gmp_get_memory_functions +__GMP_DECLSPEC void mp_get_memory_functions __GMP_PROTO ((void *(**) (size_t), + void *(**) (void *, size_t, size_t), + void (**) (void *, size_t))) __GMP_NOTHROW; +#define mp_bits_per_limb __gmp_bits_per_limb +__GMP_DECLSPEC extern __gmp_const int mp_bits_per_limb; +#define gmp_errno __gmp_errno +__GMP_DECLSPEC extern int gmp_errno; +#define gmp_version __gmp_version +__GMP_DECLSPEC extern __gmp_const char * __gmp_const gmp_version; +#define mpir_version __mpir_version +__GMP_DECLSPEC extern __gmp_const char * __gmp_const mpir_version; +/**************** Random number routines. ****************/ +#define gmp_randinit_default __gmp_randinit_default +__GMP_DECLSPEC void gmp_randinit_default __GMP_PROTO ((gmp_randstate_t)); +#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp +__GMP_DECLSPEC void gmp_randinit_lc_2exp __GMP_PROTO ((gmp_randstate_t, + mpz_srcptr, mpir_ui, + mp_bitcnt_t)); +#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size +__GMP_DECLSPEC int gmp_randinit_lc_2exp_size __GMP_PROTO ((gmp_randstate_t, mp_bitcnt_t)); +#define gmp_randinit_mt __gmp_randinit_mt +__GMP_DECLSPEC void gmp_randinit_mt __GMP_PROTO ((gmp_randstate_t)); +#define gmp_randinit_set __gmp_randinit_set +__GMP_DECLSPEC void gmp_randinit_set __GMP_PROTO ((gmp_randstate_t, __gmp_const __gmp_randstate_struct *)); +#define gmp_randseed __gmp_randseed +__GMP_DECLSPEC void gmp_randseed __GMP_PROTO ((gmp_randstate_t, mpz_srcptr)); +#define gmp_randseed_ui __gmp_randseed_ui +__GMP_DECLSPEC void gmp_randseed_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +#define gmp_randclear __gmp_randclear +__GMP_DECLSPEC void gmp_randclear __GMP_PROTO ((gmp_randstate_t)); +#define gmp_urandomb_ui __gmp_urandomb_ui +__GMP_DECLSPEC mpir_ui gmp_urandomb_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +#define gmp_urandomm_ui __gmp_urandomm_ui +__GMP_DECLSPEC mpir_ui gmp_urandomm_ui __GMP_PROTO ((gmp_randstate_t, mpir_ui)); +/**************** Formatted output routines. ****************/ +#define gmp_asprintf __gmp_asprintf +__GMP_DECLSPEC int gmp_asprintf __GMP_PROTO ((char **, __gmp_const char *, ...)); +#define gmp_fprintf __gmp_fprintf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif +#define gmp_obstack_printf __gmp_obstack_printf +#if defined (_GMP_H_HAVE_OBSTACK) +__GMP_DECLSPEC int gmp_obstack_printf __GMP_PROTO ((struct obstack *, __gmp_const char *, ...)); +#endif +#define gmp_obstack_vprintf __gmp_obstack_vprintf +#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, __gmp_const char *, va_list)); +#endif +#define gmp_printf __gmp_printf +__GMP_DECLSPEC int gmp_printf __GMP_PROTO ((__gmp_const char *, ...)); +#define gmp_snprintf __gmp_snprintf +__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, ...)); +#define gmp_sprintf __gmp_sprintf +__GMP_DECLSPEC int gmp_sprintf __GMP_PROTO ((char *, __gmp_const char *, ...)); +#define gmp_vasprintf __gmp_vasprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, __gmp_const char *, va_list)); +#endif +#define gmp_vfprintf __gmp_vfprintf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif +#define gmp_vprintf __gmp_vprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif +#define gmp_vsnprintf __gmp_vsnprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, va_list)); +#endif +#define gmp_vsprintf __gmp_vsprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, __gmp_const char *, va_list)); +#endif +/**************** Formatted input routines. ****************/ +#define gmp_fscanf __gmp_fscanf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif +#define gmp_scanf __gmp_scanf +__GMP_DECLSPEC int gmp_scanf __GMP_PROTO ((__gmp_const char *, ...)); +#define gmp_sscanf __gmp_sscanf +__GMP_DECLSPEC int gmp_sscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, ...)); +#define gmp_vfscanf __gmp_vfscanf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif +#define gmp_vscanf __gmp_vscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif +#define gmp_vsscanf __gmp_vsscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, va_list)); +#endif +/**************** Integer (i.e. Z) routines. ****************/ +#define _mpz_realloc __gmpz_realloc +#define mpz_realloc __gmpz_realloc +__GMP_DECLSPEC void *_mpz_realloc __GMP_PROTO ((mpz_ptr, mp_size_t)); +#define mpz_abs __gmpz_abs +#define __GMP_MPZ_ABS_MIN_ALLOC(x,y) (__GMP_ABS(y->_mp_size)) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs) +__GMP_DECLSPEC void mpz_abs __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif +#define __GMP_MPZ_ADD_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),__GMP_ABS(z->_mp_size))+1) +#define mpz_add __gmpz_add +__GMP_DECLSPEC void mpz_add __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define __GMP_MPZ_ADD_UI_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_add_ui __gmpz_add_ui +__GMP_DECLSPEC void mpz_add_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_addmul __gmpz_addmul +__GMP_DECLSPEC void mpz_addmul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_addmul_ui __gmpz_addmul_ui +__GMP_DECLSPEC void mpz_addmul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_and __gmpz_and +__GMP_DECLSPEC void mpz_and __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_array_init __gmpz_array_init +__GMP_DECLSPEC void mpz_array_init __GMP_PROTO ((mpz_ptr, mp_size_t, mp_size_t)); +#define mpz_bin_ui __gmpz_bin_ui +__GMP_DECLSPEC void mpz_bin_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_bin_uiui __gmpz_bin_uiui +__GMP_DECLSPEC void mpz_bin_uiui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_cdiv_q __gmpz_cdiv_q +__GMP_DECLSPEC void mpz_cdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp +__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_qr __gmpz_cdiv_qr +__GMP_DECLSPEC void mpz_cdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_r __gmpz_cdiv_r +__GMP_DECLSPEC void mpz_cdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp +__GMP_DECLSPEC void mpz_cdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_cdiv_ui __gmpz_cdiv_ui +__GMP_DECLSPEC mpir_ui mpz_cdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_clear __gmpz_clear +__GMP_DECLSPEC void mpz_clear __GMP_PROTO ((mpz_ptr)); +#define mpz_clears __gmpz_clears +__GMP_DECLSPEC void mpz_clears __GMP_PROTO ((mpz_ptr, ...)); +#define mpz_clrbit __gmpz_clrbit +__GMP_DECLSPEC void mpz_clrbit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_cmp __gmpz_cmp +__GMP_DECLSPEC int mpz_cmp __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmp_d __gmpz_cmp_d +__GMP_DECLSPEC int mpz_cmp_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define _mpz_cmp_si __gmpz_cmp_si +__GMP_DECLSPEC int _mpz_cmp_si __GMP_PROTO ((mpz_srcptr, mpir_si)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define _mpz_cmp_ui __gmpz_cmp_ui +__GMP_DECLSPEC int _mpz_cmp_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs __gmpz_cmpabs +__GMP_DECLSPEC int mpz_cmpabs __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs_d __gmpz_cmpabs_d +__GMP_DECLSPEC int mpz_cmpabs_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define mpz_cmpabs_ui __gmpz_cmpabs_ui +__GMP_DECLSPEC int mpz_cmpabs_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_com __gmpz_com +__GMP_DECLSPEC void mpz_com __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_combit __gmpz_combit +__GMP_DECLSPEC void mpz_combit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_congruent_p __gmpz_congruent_p +__GMP_DECLSPEC int mpz_congruent_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p +__GMP_DECLSPEC int mpz_congruent_2exp_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_congruent_ui_p __gmpz_congruent_ui_p +__GMP_DECLSPEC int mpz_congruent_ui_p __GMP_PROTO ((mpz_srcptr, mpir_ui, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_divexact __gmpz_divexact +__GMP_DECLSPEC void mpz_divexact __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_divexact_ui __gmpz_divexact_ui +__GMP_DECLSPEC void mpz_divexact_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_divisible_p __gmpz_divisible_p +__GMP_DECLSPEC int mpz_divisible_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_divisible_ui_p __gmpz_divisible_ui_p +__GMP_DECLSPEC int mpz_divisible_ui_p __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p +__GMP_DECLSPEC int mpz_divisible_2exp_p __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_dump __gmpz_dump +__GMP_DECLSPEC void mpz_dump __GMP_PROTO ((mpz_srcptr)); +#define mpz_export __gmpz_export +__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, int, size_t, mpz_srcptr)); +#define mpz_fac_ui __gmpz_fac_ui +__GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_2fac_ui __gmpz_2fac_ui +__GMP_DECLSPEC void mpz_2fac_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_mfac_uiui __gmpz_mfac_uiui +__GMP_DECLSPEC void mpz_mfac_uiui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_primorial_ui __gmpz_primorial_ui +__GMP_DECLSPEC void mpz_primorial_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_fdiv_q __gmpz_fdiv_q +__GMP_DECLSPEC void mpz_fdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp +__GMP_DECLSPEC void mpz_fdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_qr __gmpz_fdiv_qr +__GMP_DECLSPEC void mpz_fdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_r __gmpz_fdiv_r +__GMP_DECLSPEC void mpz_fdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp +__GMP_DECLSPEC void mpz_fdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_fdiv_ui __gmpz_fdiv_ui +__GMP_DECLSPEC mpir_ui mpz_fdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_fib_ui __gmpz_fib_ui +__GMP_DECLSPEC void mpz_fib_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_fib2_ui __gmpz_fib2_ui +__GMP_DECLSPEC void mpz_fib2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpir_ui)); +#define mpz_fits_sint_p __gmpz_fits_sint_p +__GMP_DECLSPEC int mpz_fits_sint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_si_p __gmpz_fits_si_p +__GMP_DECLSPEC int mpz_fits_si_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_slong_p __gmpz_fits_slong_p +__GMP_DECLSPEC int mpz_fits_slong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_sshort_p __gmpz_fits_sshort_p +__GMP_DECLSPEC int mpz_fits_sshort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_fits_uint_p __gmpz_fits_uint_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_DECLSPEC int mpz_fits_uint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ui_p __gmpz_fits_ui_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ui_p) +__GMP_DECLSPEC int mpz_fits_ui_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ulong_p __gmpz_fits_ulong_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_DECLSPEC int mpz_fits_ulong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_fits_ushort_p __gmpz_fits_ushort_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_DECLSPEC int mpz_fits_ushort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_gcd __gmpz_gcd +__GMP_DECLSPEC void mpz_gcd __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_gcd_ui __gmpz_gcd_ui +__GMP_DECLSPEC mpir_ui mpz_gcd_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_gcdext __gmpz_gcdext +__GMP_DECLSPEC void mpz_gcdext __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_get_d __gmpz_get_d +__GMP_DECLSPEC double mpz_get_d __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_get_d_2exp __gmpz_get_d_2exp +__GMP_DECLSPEC double mpz_get_d_2exp __GMP_PROTO ((signed long *, mpz_srcptr)); +#define mpz_get_si __gmpz_get_si +__GMP_DECLSPEC /* signed */ mpir_si mpz_get_si __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_get_str __gmpz_get_str +__GMP_DECLSPEC char *mpz_get_str __GMP_PROTO ((char *, int, mpz_srcptr)); +#define mpz_get_ui __gmpz_get_ui +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui) +__GMP_DECLSPEC mpir_ui mpz_get_ui __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_getlimbn __gmpz_getlimbn +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn) +__GMP_DECLSPEC mp_limb_t mpz_getlimbn __GMP_PROTO ((mpz_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_hamdist __gmpz_hamdist +__GMP_DECLSPEC mp_bitcnt_t mpz_hamdist __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_import __gmpz_import +__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, size_t, int, size_t, int, size_t, __gmp_const void *)); +#define mpz_init __gmpz_init +__GMP_DECLSPEC void mpz_init __GMP_PROTO ((mpz_ptr)); +#define mpz_init2 __gmpz_init2 +__GMP_DECLSPEC void mpz_init2 __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_inits __gmpz_inits +__GMP_DECLSPEC void mpz_inits __GMP_PROTO ((mpz_ptr, ...)); +#define mpz_init_set __gmpz_init_set +__GMP_DECLSPEC void mpz_init_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_init_set_d __gmpz_init_set_d +__GMP_DECLSPEC void mpz_init_set_d __GMP_PROTO ((mpz_ptr, double)); +#define mpz_init_set_si __gmpz_init_set_si +__GMP_DECLSPEC void mpz_init_set_si __GMP_PROTO ((mpz_ptr, mpir_si)); +#define mpz_init_set_str __gmpz_init_set_str +__GMP_DECLSPEC int mpz_init_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); +#define mpz_init_set_ui __gmpz_init_set_ui +__GMP_DECLSPEC void mpz_init_set_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_inp_raw __gmpz_inp_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, FILE *)); +#endif +#define mpz_inp_str __gmpz_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, FILE *, int)); +#endif +#define mpz_invert __gmpz_invert +__GMP_DECLSPEC int mpz_invert __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_ior __gmpz_ior +__GMP_DECLSPEC void mpz_ior __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_jacobi __gmpz_jacobi +__GMP_DECLSPEC int mpz_jacobi __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_kronecker mpz_jacobi /* alias */ +#define mpz_kronecker_si __gmpz_kronecker_si +__GMP_DECLSPEC int mpz_kronecker_si __GMP_PROTO ((mpz_srcptr, mpir_si)) __GMP_ATTRIBUTE_PURE; +#define mpz_kronecker_ui __gmpz_kronecker_ui +__GMP_DECLSPEC int mpz_kronecker_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_si_kronecker __gmpz_si_kronecker +__GMP_DECLSPEC int mpz_si_kronecker __GMP_PROTO ((mpir_si, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_ui_kronecker __gmpz_ui_kronecker +__GMP_DECLSPEC int mpz_ui_kronecker __GMP_PROTO ((mpir_ui, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_lcm __gmpz_lcm +__GMP_DECLSPEC void mpz_lcm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_lcm_ui __gmpz_lcm_ui +__GMP_DECLSPEC void mpz_lcm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_legendre mpz_jacobi /* alias */ +#define mpz_lucnum_ui __gmpz_lucnum_ui +__GMP_DECLSPEC void mpz_lucnum_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_lucnum2_ui __gmpz_lucnum2_ui +__GMP_DECLSPEC void mpz_lucnum2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpir_ui)); +#define mpz_millerrabin __gmpz_millerrabin +__GMP_DECLSPEC int mpz_millerrabin __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; +#define mpz_miller_rabin __gmpz_miller_rabin +__GMP_DECLSPEC int mpz_miller_rabin __GMP_PROTO ((mpz_srcptr, int, gmp_randstate_t)) __GMP_ATTRIBUTE_PURE; +#define mpz_mod __gmpz_mod +__GMP_DECLSPEC void mpz_mod __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */ +#define __GMP_MPZ_MUL_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+__GMP_ABS(z->_mp_size)+1) +#define mpz_mul __gmpz_mul +__GMP_DECLSPEC void mpz_mul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_mul_2exp __gmpz_mul_2exp +__GMP_DECLSPEC void mpz_mul_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define __GMP_MPZ_MUL_SI_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS+1) +#define mpz_mul_si __gmpz_mul_si +__GMP_DECLSPEC void mpz_mul_si __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_si)); +#define __GMP_MPZ_MUL_UI_MIN_ALLOC(x,y,z) (__GMP_ABS(y->_mp_size)+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS+1) +#define mpz_mul_ui __gmpz_mul_ui +__GMP_DECLSPEC void mpz_mul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_neg __gmpz_neg +#define __GMP_MPZ_NEG_MIN_ALLOC(x,y) (__GMP_ABS(y->_mp_size)) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg) +__GMP_DECLSPEC void mpz_neg __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif +#define mpz_nextprime __gmpz_nextprime +__GMP_DECLSPEC void mpz_nextprime __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_next_prime_candidate __gmpz_next_prime_candidate +__GMP_DECLSPEC void mpz_next_prime_candidate __GMP_PROTO ((mpz_ptr, mpz_srcptr, gmp_randstate_t)); +#define mpz_out_raw __gmpz_out_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_raw __GMP_PROTO ((FILE *, mpz_srcptr)); +#endif +#define mpz_out_str __gmpz_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_str __GMP_PROTO ((FILE *, int, mpz_srcptr)); +#endif +#define mpz_perfect_power_p __gmpz_perfect_power_p +__GMP_DECLSPEC int mpz_perfect_power_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpz_perfect_square_p __gmpz_perfect_square_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_DECLSPEC int mpz_perfect_square_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_popcount __gmpz_popcount +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount) +__GMP_DECLSPEC mp_bitcnt_t mpz_popcount __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_pow_ui __gmpz_pow_ui +__GMP_DECLSPEC void mpz_pow_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_powm __gmpz_powm +__GMP_DECLSPEC void mpz_powm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr)); +#define mpz_powm_ui __gmpz_powm_ui +__GMP_DECLSPEC void mpz_powm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui, mpz_srcptr)); +#define mpz_probab_prime_p __gmpz_probab_prime_p +__GMP_DECLSPEC int mpz_probab_prime_p __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; +#define mpz_probable_prime_p __gmpz_probable_prime_p +__GMP_DECLSPEC int mpz_probable_prime_p __GMP_PROTO ((mpz_srcptr,gmp_randstate_t, int, mpir_ui)); +#define mpz_likely_prime_p __gmpz_likely_prime_p +__GMP_DECLSPEC int mpz_likely_prime_p __GMP_PROTO ((mpz_srcptr,gmp_randstate_t, mpir_ui)); +#define mpz_realloc2 __gmpz_realloc2 +__GMP_DECLSPEC void mpz_realloc2 __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_remove __gmpz_remove +__GMP_DECLSPEC mp_bitcnt_t mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_root __gmpz_root +__GMP_DECLSPEC int mpz_root __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_nthroot __gmpz_nthroot +__GMP_DECLSPEC void mpz_nthroot __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_rootrem __gmpz_rootrem +__GMP_DECLSPEC void mpz_rootrem __GMP_PROTO ((mpz_ptr,mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_rrandomb __gmpz_rrandomb +__GMP_DECLSPEC void mpz_rrandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mp_bitcnt_t)); +#define mpz_scan0 __gmpz_scan0 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan0 __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_scan1 __gmpz_scan1 +__GMP_DECLSPEC mp_bitcnt_t mpz_scan1 __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define __GMP_MPZ_SET_MIN_ALLOC(x,y) __GMP_ABS(y->_mp_size) +#define mpz_set __gmpz_set +__GMP_DECLSPEC void mpz_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_set_d __gmpz_set_d +__GMP_DECLSPEC void mpz_set_d __GMP_PROTO ((mpz_ptr, double)); +#define mpz_set_f __gmpz_set_f +__GMP_DECLSPEC void mpz_set_f __GMP_PROTO ((mpz_ptr, mpf_srcptr)); +#define mpz_set_q __gmpz_set_q +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q) +__GMP_DECLSPEC void mpz_set_q __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#endif +#define __GMP_MPZ_SET_SI_MIN_ALLOC(x,y) (1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS) +#define mpz_set_si __gmpz_set_si +__GMP_DECLSPEC void mpz_set_si __GMP_PROTO ((mpz_ptr, mpir_si)); +#define mpz_set_str __gmpz_set_str +__GMP_DECLSPEC int mpz_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); +#define __GMP_MPZ_SET_UI_MIN_ALLOC(x,y) (1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS) +#define mpz_set_ui __gmpz_set_ui +__GMP_DECLSPEC void mpz_set_ui __GMP_PROTO ((mpz_ptr, mpir_ui)); +#define mpz_setbit __gmpz_setbit +__GMP_DECLSPEC void mpz_setbit __GMP_PROTO ((mpz_ptr, mp_bitcnt_t)); +#define mpz_size __gmpz_size +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size) +__GMP_DECLSPEC size_t mpz_size __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpz_sizeinbase __gmpz_sizeinbase +__GMP_DECLSPEC size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_sqrt __gmpz_sqrt +__GMP_DECLSPEC void mpz_sqrt __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#define mpz_sqrtrem __gmpz_sqrtrem +__GMP_DECLSPEC void mpz_sqrtrem __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr)); +#define __GMP_MPZ_SUB_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),__GMP_ABS(z->_mp_size))+1) +#define mpz_sub __gmpz_sub +__GMP_DECLSPEC void mpz_sub __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define __GMP_MPZ_SUB_UI_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(y->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_sub_ui __gmpz_sub_ui +__GMP_DECLSPEC void mpz_sub_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define __GMP_MPZ_UI_SUB_MIN_ALLOC(x,y,z) (__GMP_MAX(__GMP_ABS(z->_mp_size),1+(GMP_BITS_PER_UI-1)/GMP_NUMB_BITS)+1) +#define mpz_ui_sub __gmpz_ui_sub +__GMP_DECLSPEC void mpz_ui_sub __GMP_PROTO ((mpz_ptr, mpir_ui, mpz_srcptr)); +#define mpz_submul __gmpz_submul +__GMP_DECLSPEC void mpz_submul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_submul_ui __gmpz_submul_ui +__GMP_DECLSPEC void mpz_submul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_swap __gmpz_swap +__GMP_DECLSPEC void mpz_swap __GMP_PROTO ((mpz_ptr, mpz_ptr)) __GMP_NOTHROW; +#define mpz_tdiv_ui __gmpz_tdiv_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_ui __GMP_PROTO ((mpz_srcptr, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpz_tdiv_q __gmpz_tdiv_q +__GMP_DECLSPEC void mpz_tdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp +__GMP_DECLSPEC void mpz_tdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tdiv_qr __gmpz_tdiv_qr +__GMP_DECLSPEC void mpz_tdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tdiv_r __gmpz_tdiv_r +__GMP_DECLSPEC void mpz_tdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp +__GMP_DECLSPEC void mpz_tdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, mp_bitcnt_t)); +#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui +__GMP_DECLSPEC mpir_ui mpz_tdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpir_ui)); +#define mpz_tstbit __gmpz_tstbit +__GMP_DECLSPEC int mpz_tstbit __GMP_PROTO ((mpz_srcptr, mp_bitcnt_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpz_ui_pow_ui __gmpz_ui_pow_ui +__GMP_DECLSPEC void mpz_ui_pow_ui __GMP_PROTO ((mpz_ptr, mpir_ui, mpir_ui)); +#define mpz_urandomb __gmpz_urandomb +__GMP_DECLSPEC void mpz_urandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mp_bitcnt_t)); +#define mpz_urandomm __gmpz_urandomm +__GMP_DECLSPEC void mpz_urandomm __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mpz_srcptr)); +#define mpz_xor __gmpz_xor +#define mpz_eor __gmpz_xor +__GMP_DECLSPEC void mpz_xor __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); +#define mpz_limbs_read __gmpz_limbs_read +__GMP_DECLSPEC mp_srcptr mpz_limbs_read (mpz_srcptr); +#define mpz_limbs_write __gmpz_limbs_write +__GMP_DECLSPEC mp_ptr mpz_limbs_write (mpz_ptr, mp_size_t); +#define mpz_limbs_modify __gmpz_limbs_modify +__GMP_DECLSPEC mp_ptr mpz_limbs_modify (mpz_ptr, mp_size_t); +#define mpz_limbs_finish __gmpz_limbs_finish +__GMP_DECLSPEC void mpz_limbs_finish (mpz_ptr, mp_size_t); +#define mpz_roinit_n __gmpz_roinit_n +__GMP_DECLSPEC mpz_srcptr mpz_roinit_n (mpz_ptr, mp_srcptr, mp_size_t); +#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }} +/****** Integer (i.e. Z) routines for intmaax_t/uintmax_t types ******/ +/* if stdint.h is available -- n.b: we do NOT include stdint.h ourselves */ +#if defined(INTMAX_MAX) +#define __GMP_BITS_PER_UINTMAX (8*sizeof(uintmax_t)) +#define mpz_get_ux __gmpz_get_ux +__GMP_DECLSPEC uintmax_t mpz_get_ux __GMP_PROTO ((mpz_srcptr)); +#define mpz_get_sx __gmpz_get_sx +__GMP_DECLSPEC intmax_t mpz_get_sx __GMP_PROTO ((mpz_srcptr)); +#define mpz_set_ux __gmpz_set_ux +__GMP_DECLSPEC void mpz_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t)); +#define mpz_set_sx __gmpz_set_sx +__GMP_DECLSPEC void mpz_set_sx __GMP_PROTO ((mpz_ptr, intmax_t)); +#define mpz_init_set_ux __gmpz_init_set_ux +__GMP_DECLSPEC void mpz_init_set_ux __GMP_PROTO ((mpz_ptr, uintmax_t)); +#define mpz_init_set_sx __gmpz_init_set_sx +__GMP_DECLSPEC void mpz_init_set_sx __GMP_PROTO ((mpz_ptr, intmax_t)); +#endif +/**************** Rational (i.e. Q) routines. ****************/ +#define mpq_abs __gmpq_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs) +__GMP_DECLSPEC void mpq_abs __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif +#define mpq_add __gmpq_add +__GMP_DECLSPEC void mpq_add __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_canonicalize __gmpq_canonicalize +__GMP_DECLSPEC void mpq_canonicalize __GMP_PROTO ((mpq_ptr)); +#define mpq_clear __gmpq_clear +__GMP_DECLSPEC void mpq_clear __GMP_PROTO ((mpq_ptr)); +#define mpq_clears __gmpq_clears +__GMP_DECLSPEC void mpq_clears __GMP_PROTO ((mpq_ptr, ...)); +#define mpq_cmp __gmpq_cmp +__GMP_DECLSPEC int mpq_cmp __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_ATTRIBUTE_PURE; +#define _mpq_cmp_si __gmpq_cmp_si +__GMP_DECLSPEC int _mpq_cmp_si __GMP_PROTO ((mpq_srcptr, mpir_si, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define _mpq_cmp_ui __gmpq_cmp_ui +__GMP_DECLSPEC int _mpq_cmp_ui __GMP_PROTO ((mpq_srcptr, mpir_ui, mpir_ui)) __GMP_ATTRIBUTE_PURE; +#define mpq_cmp_z __gmpq_cmp_z +__GMP_DECLSPEC int mpq_cmp_z (mpq_srcptr, mpz_srcptr) __GMP_ATTRIBUTE_PURE; +#define mpq_div __gmpq_div +__GMP_DECLSPEC void mpq_div __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_div_2exp __gmpq_div_2exp +__GMP_DECLSPEC void mpq_div_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, mp_bitcnt_t)); +#define mpq_equal __gmpq_equal +__GMP_DECLSPEC int mpq_equal __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpq_get_num __gmpq_get_num +__GMP_DECLSPEC void mpq_get_num __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#define mpq_get_den __gmpq_get_den +__GMP_DECLSPEC void mpq_get_den __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#define mpq_get_d __gmpq_get_d +__GMP_DECLSPEC double mpq_get_d __GMP_PROTO ((mpq_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpq_get_str __gmpq_get_str +__GMP_DECLSPEC char *mpq_get_str __GMP_PROTO ((char *, int, mpq_srcptr)); +#define mpq_init __gmpq_init +__GMP_DECLSPEC void mpq_init __GMP_PROTO ((mpq_ptr)); +#define mpq_inits __gmpq_inits +__GMP_DECLSPEC void mpq_inits __GMP_PROTO ((mpq_ptr, ...)); +#define mpq_inp_str __gmpq_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, FILE *, int)); +#endif +#define mpq_inv __gmpq_inv +__GMP_DECLSPEC void mpq_inv __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#define mpq_mul __gmpq_mul +__GMP_DECLSPEC void mpq_mul __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_mul_2exp __gmpq_mul_2exp +__GMP_DECLSPEC void mpq_mul_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, mp_bitcnt_t)); +#define mpq_neg __gmpq_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg) +__GMP_DECLSPEC void mpq_neg __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif +#define mpq_out_str __gmpq_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_out_str __GMP_PROTO ((FILE *, int, mpq_srcptr)); +#endif +#define mpq_set __gmpq_set +__GMP_DECLSPEC void mpq_set __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#define mpq_set_d __gmpq_set_d +__GMP_DECLSPEC void mpq_set_d __GMP_PROTO ((mpq_ptr, double)); +#define mpq_set_den __gmpq_set_den +__GMP_DECLSPEC void mpq_set_den __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_set_f __gmpq_set_f +__GMP_DECLSPEC void mpq_set_f __GMP_PROTO ((mpq_ptr, mpf_srcptr)); +#define mpq_set_num __gmpq_set_num +__GMP_DECLSPEC void mpq_set_num __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_set_si __gmpq_set_si +__GMP_DECLSPEC void mpq_set_si __GMP_PROTO ((mpq_ptr, mpir_si, mpir_ui)); +#define mpq_set_str __gmpq_set_str +__GMP_DECLSPEC int mpq_set_str __GMP_PROTO ((mpq_ptr, __gmp_const char *, int)); +#define mpq_set_ui __gmpq_set_ui +__GMP_DECLSPEC void mpq_set_ui __GMP_PROTO ((mpq_ptr, mpir_ui, mpir_ui)); +#define mpq_set_z __gmpq_set_z +__GMP_DECLSPEC void mpq_set_z __GMP_PROTO ((mpq_ptr, mpz_srcptr)); +#define mpq_sub __gmpq_sub +__GMP_DECLSPEC void mpq_sub __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); +#define mpq_swap __gmpq_swap +__GMP_DECLSPEC void mpq_swap __GMP_PROTO ((mpq_ptr, mpq_ptr)) __GMP_NOTHROW; +/**************** Float (i.e. F) routines. ****************/ +#define mpf_abs __gmpf_abs +__GMP_DECLSPEC void mpf_abs __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_add __gmpf_add +__GMP_DECLSPEC void mpf_add __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_add_ui __gmpf_add_ui +__GMP_DECLSPEC void mpf_add_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_ceil __gmpf_ceil +__GMP_DECLSPEC void mpf_ceil __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_clear __gmpf_clear +__GMP_DECLSPEC void mpf_clear __GMP_PROTO ((mpf_ptr)); +#define mpf_clears __gmpf_clears +__GMP_DECLSPEC void mpf_clears __GMP_PROTO ((mpf_ptr, ...)); +#define mpf_cmp __gmpf_cmp +__GMP_DECLSPEC int mpf_cmp __GMP_PROTO ((mpf_srcptr, mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_d __gmpf_cmp_d +__GMP_DECLSPEC int mpf_cmp_d __GMP_PROTO ((mpf_srcptr, double)) __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_si __gmpf_cmp_si +__GMP_DECLSPEC int mpf_cmp_si __GMP_PROTO ((mpf_srcptr, mpir_si)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_cmp_ui __gmpf_cmp_ui +__GMP_DECLSPEC int mpf_cmp_ui __GMP_PROTO ((mpf_srcptr, mpir_ui)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_div __gmpf_div +__GMP_DECLSPEC void mpf_div __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_div_2exp __gmpf_div_2exp +__GMP_DECLSPEC void mpf_div_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, mp_bitcnt_t)); +#define mpf_div_ui __gmpf_div_ui +__GMP_DECLSPEC void mpf_div_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_dump __gmpf_dump +__GMP_DECLSPEC void mpf_dump __GMP_PROTO ((mpf_srcptr)); +#define mpf_eq __gmpf_eq +__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpf_fits_sint_p __gmpf_fits_sint_p +__GMP_DECLSPEC int mpf_fits_sint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_si_p __gmpf_fits_si_p +__GMP_DECLSPEC int mpf_fits_si_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_slong_p __gmpf_fits_slong_p +__GMP_DECLSPEC int mpf_fits_slong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_sshort_p __gmpf_fits_sshort_p +__GMP_DECLSPEC int mpf_fits_sshort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_uint_p __gmpf_fits_uint_p +__GMP_DECLSPEC int mpf_fits_uint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ui_p __gmpf_fits_ui_p +__GMP_DECLSPEC int mpf_fits_ui_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ulong_p __gmpf_fits_ulong_p +__GMP_DECLSPEC int mpf_fits_ulong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_fits_ushort_p __gmpf_fits_ushort_p +__GMP_DECLSPEC int mpf_fits_ushort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_floor __gmpf_floor +__GMP_DECLSPEC void mpf_floor __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_get_d __gmpf_get_d +__GMP_DECLSPEC double mpf_get_d __GMP_PROTO ((mpf_srcptr)) __GMP_ATTRIBUTE_PURE; +#define mpf_get_d_2exp __gmpf_get_d_2exp +__GMP_DECLSPEC double mpf_get_d_2exp __GMP_PROTO ((signed long *, mpf_srcptr)); +#define mpf_get_default_prec __gmpf_get_default_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_default_prec __GMP_PROTO ((void)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_prec __gmpf_get_prec +__GMP_DECLSPEC mp_bitcnt_t mpf_get_prec __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_si __gmpf_get_si +__GMP_DECLSPEC mpir_si mpf_get_si __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_get_str __gmpf_get_str +__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr)); +#define mpf_get_ui __gmpf_get_ui +__GMP_DECLSPEC mpir_ui mpf_get_ui __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_init __gmpf_init +__GMP_DECLSPEC void mpf_init __GMP_PROTO ((mpf_ptr)); +#define mpf_init2 __gmpf_init2 +__GMP_DECLSPEC void mpf_init2 __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)); +#define mpf_inits __gmpf_inits +__GMP_DECLSPEC void mpf_inits __GMP_PROTO ((mpf_ptr, ...)); +#define mpf_init_set __gmpf_init_set +__GMP_DECLSPEC void mpf_init_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_init_set_d __gmpf_init_set_d +__GMP_DECLSPEC void mpf_init_set_d __GMP_PROTO ((mpf_ptr, double)); +#define mpf_init_set_si __gmpf_init_set_si +__GMP_DECLSPEC void mpf_init_set_si __GMP_PROTO ((mpf_ptr, mpir_si)); +#define mpf_init_set_str __gmpf_init_set_str +__GMP_DECLSPEC int mpf_init_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); +#define mpf_init_set_ui __gmpf_init_set_ui +__GMP_DECLSPEC void mpf_init_set_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_inp_str __gmpf_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, FILE *, int)); +#endif +#define mpf_integer_p __gmpf_integer_p +__GMP_DECLSPEC int mpf_integer_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_mul __gmpf_mul +__GMP_DECLSPEC void mpf_mul __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_mul_2exp __gmpf_mul_2exp +__GMP_DECLSPEC void mpf_mul_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, mp_bitcnt_t)); +#define mpf_mul_ui __gmpf_mul_ui +__GMP_DECLSPEC void mpf_mul_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_neg __gmpf_neg +__GMP_DECLSPEC void mpf_neg __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_out_str __gmpf_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_out_str __GMP_PROTO ((FILE *, int, size_t, mpf_srcptr)); +#endif +#define mpf_pow_ui __gmpf_pow_ui +__GMP_DECLSPEC void mpf_pow_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_random2 __gmpf_random2 +__GMP_DECLSPEC void mpf_random2 __GMP_PROTO ((mpf_ptr, mp_size_t, mp_exp_t)); +#define mpf_rrandomb __gmpf_rrandomb +__GMP_DECLSPEC void mpf_rrandomb __GMP_PROTO ((mpf_ptr, gmp_randstate_t, mp_size_t, mp_exp_t)); +#define mpf_reldiff __gmpf_reldiff +__GMP_DECLSPEC void mpf_reldiff __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_set __gmpf_set +__GMP_DECLSPEC void mpf_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_set_d __gmpf_set_d +__GMP_DECLSPEC void mpf_set_d __GMP_PROTO ((mpf_ptr, double)); +#define mpf_set_default_prec __gmpf_set_default_prec +__GMP_DECLSPEC void mpf_set_default_prec __GMP_PROTO ((mp_bitcnt_t)) __GMP_NOTHROW; +#define mpf_set_prec __gmpf_set_prec +__GMP_DECLSPEC void mpf_set_prec __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)); +#define mpf_set_prec_raw __gmpf_set_prec_raw +__GMP_DECLSPEC void mpf_set_prec_raw __GMP_PROTO ((mpf_ptr, mp_bitcnt_t)) __GMP_NOTHROW; +#define mpf_set_q __gmpf_set_q +__GMP_DECLSPEC void mpf_set_q __GMP_PROTO ((mpf_ptr, mpq_srcptr)); +#define mpf_set_si __gmpf_set_si +__GMP_DECLSPEC void mpf_set_si __GMP_PROTO ((mpf_ptr, mpir_si)); +#define mpf_set_str __gmpf_set_str +__GMP_DECLSPEC int mpf_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); +#define mpf_set_ui __gmpf_set_ui +__GMP_DECLSPEC void mpf_set_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_set_z __gmpf_set_z +__GMP_DECLSPEC void mpf_set_z __GMP_PROTO ((mpf_ptr, mpz_srcptr)); +#define mpf_size __gmpf_size +__GMP_DECLSPEC size_t mpf_size __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpf_sqrt __gmpf_sqrt +__GMP_DECLSPEC void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_sqrt_ui __gmpf_sqrt_ui +__GMP_DECLSPEC void mpf_sqrt_ui __GMP_PROTO ((mpf_ptr, mpir_ui)); +#define mpf_sub __gmpf_sub +__GMP_DECLSPEC void mpf_sub __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); +#define mpf_sub_ui __gmpf_sub_ui +__GMP_DECLSPEC void mpf_sub_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpir_ui)); +#define mpf_swap __gmpf_swap +__GMP_DECLSPEC void mpf_swap __GMP_PROTO ((mpf_ptr, mpf_ptr)) __GMP_NOTHROW; +#define mpf_trunc __gmpf_trunc +__GMP_DECLSPEC void mpf_trunc __GMP_PROTO ((mpf_ptr, mpf_srcptr)); +#define mpf_ui_div __gmpf_ui_div +__GMP_DECLSPEC void mpf_ui_div __GMP_PROTO ((mpf_ptr, mpir_ui, mpf_srcptr)); +#define mpf_ui_sub __gmpf_ui_sub +__GMP_DECLSPEC void mpf_ui_sub __GMP_PROTO ((mpf_ptr, mpir_ui, mpf_srcptr)); +#define mpf_urandomb __gmpf_urandomb +__GMP_DECLSPEC void mpf_urandomb __GMP_PROTO ((mpf_t, gmp_randstate_t, mp_bitcnt_t)); +/************ Low level positive-integer (i.e. N) routines. ************/ +/* This is ugly, but we need to make user calls reach the prefixed function. */ +#define mpn_add __MPN(add) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add) +__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif +#define mpn_add_1 __MPN(add_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1) +__GMP_DECLSPEC mp_limb_t mpn_add_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif +#define mpn_add_n __MPN(add_n) +__GMP_DECLSPEC mp_limb_t mpn_add_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_addmul_1 __MPN(addmul_1) +__GMP_DECLSPEC mp_limb_t mpn_addmul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_bdivmod __MPN(bdivmod) +__GMP_DECLSPEC mp_limb_t mpn_bdivmod __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mpir_ui)); +#define mpn_divrem __MPN(divrem) +__GMP_DECLSPEC mp_limb_t mpn_divrem __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_mulmod_Bexpp1 __MPN(mulmod_Bexpp1) +__GMP_DECLSPEC int mpn_mulmod_Bexpp1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_ptr)); +#define mpn_mulmod_2expp1 __MPN(mulmod_2expp1_basecase) +__GMP_DECLSPEC int mpn_mulmod_2expp1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr,int,mpir_ui, mp_ptr)); +#define mpn_mulmod_2expm1 __MPN(mulmod_2expm1) +__GMP_DECLSPEC void mpn_mulmod_2expm1 __GMP_PROTO ((mp_ptr, mp_ptr, mp_ptr, mpir_ui, mp_ptr)); +#define mpn_cmp __MPN(cmp) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp) +__GMP_DECLSPEC int mpn_cmp __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif +#define mpn_redc_1 __MPN(redc_1) +__GMP_DECLSPEC void mpn_redc_1 __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t);) +#define mpn_redc_2 __MPN(redc_2) +__GMP_DECLSPEC void mpn_redc_2 __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr)); +#define mpn_redc_n __MPN(redc_n) +__GMP_DECLSPEC void mpn_redc_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_srcptr)); +#define mpn_divexact_by3(dst,src,size) \ + mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0)) +#define mpn_divexact_by3c __MPN(divexact_by3c) +__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_divmod_1(qp,np,nsize,dlimb) \ + mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb) +#define mpn_divrem_1 __MPN(divrem_1) +__GMP_DECLSPEC mp_limb_t mpn_divrem_1 __GMP_PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_divrem_2 __MPN(divrem_2) +__GMP_DECLSPEC mp_limb_t mpn_divrem_2 __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr)); +#define mpn_invert __MPN(invert) +__GMP_DECLSPEC void mpn_invert __GMP_PROTO ((mp_ptr xp, mp_srcptr ap, mp_size_t n)); +#define mpn_sb_divappr_q __MPN(sb_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_sb_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dip)); +#define mpn_dc_bdiv_q_n __MPN(dc_bdiv_q_n) +__GMP_DECLSPEC void mpn_dc_bdiv_q_n __GMP_PROTO ((mp_ptr qp, mp_ptr wp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_limb_t dinv, mp_ptr scratch)); +#define mpn_inv_divappr_q_n __MPN(inv_divappr_q_n) +__GMP_DECLSPEC mp_limb_t mpn_inv_divappr_q_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_srcptr dip)); +#define mpn_dc_divappr_q __MPN(dc_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_dc_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, + mp_size_t n, mp_limb_t dinv)); +#define mpn_dc_div_q __MPN(dc_div_q) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_inv_divappr_q __MPN(inv_divappr_q) +__GMP_DECLSPEC mp_limb_t mpn_inv_divappr_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, mp_srcptr dp, mp_size_t n, + mp_srcptr dinv)); +#define mpn_inv_div_q __MPN(inv_div_q) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_inv_div_qr __MPN(inv_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_inv_div_qr_n __MPN(inv_div_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_inv_div_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, + mp_srcptr dp, mp_size_t dn, mp_srcptr dinv)); +#define mpn_dc_div_qr __MPN(dc_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_div_qr_n __MPN(dc_div_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_dc_div_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_srcptr dp, mp_size_t n, + mp_limb_t dinv, mp_ptr tp)); +#define mpn_sb_div_q __MPN(sb_div_q) +__GMP_DECLSPEC mp_limb_t mpn_sb_div_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_sb_bdiv_q __MPN(sb_bdiv_q) +__GMP_DECLSPEC void mpn_sb_bdiv_q __GMP_PROTO ((mp_ptr qp, mp_ptr wp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_q __MPN(dc_bdiv_q) +__GMP_DECLSPEC void mpn_dc_bdiv_q __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_qr __MPN(dc_bdiv_qr) +__GMP_DECLSPEC mp_limb_t mpn_dc_bdiv_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_dc_bdiv_qr_n __MPN(dc_bdiv_qr_n) +__GMP_DECLSPEC mp_limb_t mpn_dc_bdiv_qr_n __GMP_PROTO ((mp_ptr qp, mp_ptr np, + mp_srcptr dp, mp_size_t n, mp_limb_t dinv, mp_ptr tp)); +#define mpn_sb_div_qr __MPN(sb_div_qr) +__GMP_DECLSPEC mp_limb_t mpn_sb_div_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_sb_bdiv_qr __MPN(sb_bdiv_qr) +__GMP_DECLSPEC mp_limb_t mpn_sb_bdiv_qr __GMP_PROTO ((mp_ptr qp, mp_ptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn, mp_limb_t dinv)); +#define mpn_tdiv_q __MPN(tdiv_q) +__GMP_DECLSPEC void mpn_tdiv_q __GMP_PROTO ((mp_ptr qp, mp_srcptr np, mp_size_t nn, + mp_srcptr dp, mp_size_t dn)); +#define mpn_divexact __MPN(divexact) +__GMP_DECLSPEC void mpn_divexact __GMP_PROTO ((mp_ptr qp, + mp_srcptr np, mp_size_t nn, mp_srcptr dp, mp_size_t dn)); +#define mpn_gcd __MPN(gcd) +__GMP_DECLSPEC mp_size_t mpn_gcd __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); +#define mpn_gcd_1 __MPN(gcd_1) +__GMP_DECLSPEC mp_limb_t mpn_gcd_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_gcdext_1 __MPN(gcdext_1) +__GMP_DECLSPEC mp_limb_t mpn_gcdext_1 __GMP_PROTO ((mp_limb_signed_t *, mp_limb_signed_t *, mp_limb_t, mp_limb_t)); +#define mpn_gcdext __MPN(gcdext) +__GMP_DECLSPEC mp_size_t mpn_gcdext __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); +#define mpn_get_str __MPN(get_str) +__GMP_DECLSPEC size_t mpn_get_str __GMP_PROTO ((unsigned char *, int, mp_ptr, mp_size_t)); +#define mpn_hamdist __MPN(hamdist) +__GMP_DECLSPEC mp_bitcnt_t mpn_hamdist __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpn_lshift __MPN(lshift) +__GMP_DECLSPEC mp_limb_t mpn_lshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); +#define mpn_mod_1 __MPN(mod_1) +__GMP_DECLSPEC mp_limb_t mpn_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_mul __MPN(mul) +__GMP_DECLSPEC mp_limb_t mpn_mul __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_mul_1 __MPN(mul_1) +__GMP_DECLSPEC mp_limb_t mpn_mul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_mul_n __MPN(mul_n) +__GMP_DECLSPEC void mpn_mul_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_sqr __MPN(sqr) +__GMP_DECLSPEC void mpn_sqr __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_neg_n __MPN(neg_n) +#define mpn_neg __MPN(neg_n) +__GMP_DECLSPEC mp_limb_t mpn_neg_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_com_n __MPN(com_n) +#define mpn_com __MPN(com_n) +__GMP_DECLSPEC void mpn_com_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_perfect_square_p __MPN(perfect_square_p) +__GMP_DECLSPEC int mpn_perfect_square_p __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_popcount __MPN(popcount) +__GMP_DECLSPEC mp_bitcnt_t mpn_popcount __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#define mpn_pow_1 __MPN(pow_1) +__GMP_DECLSPEC mp_size_t mpn_pow_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr)); +/* undocumented now, but retained here for upward compatibility */ +#define mpn_preinv_mod_1 __MPN(preinv_mod_1) +__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_random __MPN(random) +__GMP_DECLSPEC void mpn_random __GMP_PROTO ((mp_ptr, mp_size_t)); +#define mpn_random2 __MPN(random2) +__GMP_DECLSPEC void mpn_random2 __GMP_PROTO ((mp_ptr, mp_size_t)); +#define mpn_urandomb __MPN(urandomb) +__GMP_DECLSPEC void mpn_urandomb __GMP_PROTO ((mp_ptr, gmp_randstate_t, mpir_ui)); +#define mpn_urandomm __MPN(urandomm) +__GMP_DECLSPEC void mpn_urandomm __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_srcptr, mp_size_t)); +#define mpn_randomb __MPN(randomb) +__GMP_DECLSPEC void mpn_randomb __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_size_t)); +#define mpn_rrandom __MPN(rrandom) +__GMP_DECLSPEC void mpn_rrandom __GMP_PROTO ((mp_ptr, gmp_randstate_t, mp_size_t)); +#define mpn_rshift __MPN(rshift) +__GMP_DECLSPEC mp_limb_t mpn_rshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); +#define mpn_scan0 __MPN(scan0) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan0 __GMP_PROTO ((mp_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_scan1 __MPN(scan1) +__GMP_DECLSPEC mp_bitcnt_t mpn_scan1 __GMP_PROTO ((mp_srcptr, mp_bitcnt_t)) __GMP_ATTRIBUTE_PURE; +#define mpn_set_str __MPN(set_str) +__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned char *, size_t, int)); +#define mpn_sizeinbase __MPN(sizeinbase) +__GMP_DECLSPEC size_t mpn_sizeinbase (mp_srcptr, mp_size_t, int); +#define mpn_sqrtrem __MPN(sqrtrem) +__GMP_DECLSPEC mp_size_t mpn_sqrtrem __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_sub __MPN(sub) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub) +__GMP_DECLSPEC mp_limb_t mpn_sub __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif +#define mpn_sub_1 __MPN(sub_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1) +__GMP_DECLSPEC mp_limb_t mpn_sub_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif +#define mpn_sub_n __MPN(sub_n) +__GMP_DECLSPEC mp_limb_t mpn_sub_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_submul_1 __MPN(submul_1) +__GMP_DECLSPEC mp_limb_t mpn_submul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); +#define mpn_tdiv_qr __MPN(tdiv_qr) +__GMP_DECLSPEC void mpn_tdiv_qr __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); +#define mpn_and_n __MPN(and_n) +__GMP_DECLSPEC void mpn_and_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_andn_n __MPN(andn_n) +__GMP_DECLSPEC void mpn_andn_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_nand_n __MPN(nand_n) +__GMP_DECLSPEC void mpn_nand_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_ior_n __MPN(ior_n) +__GMP_DECLSPEC void mpn_ior_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_iorn_n __MPN(iorn_n) +__GMP_DECLSPEC void mpn_iorn_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_nior_n __MPN(nior_n) +__GMP_DECLSPEC void mpn_nior_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_xor_n __MPN(xor_n) +__GMP_DECLSPEC void mpn_xor_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_xnor_n __MPN(xnor_n) +__GMP_DECLSPEC void mpn_xnor_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#define mpn_copyi __MPN(copyi) +__GMP_DECLSPEC void mpn_copyi __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_copyd __MPN(copyd) +__GMP_DECLSPEC void mpn_copyd __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t)); +#define mpn_zero __MPN(zero) +__GMP_DECLSPEC void mpn_zero __GMP_PROTO ((mp_ptr, mp_size_t)); +#ifndef mpn_sumdiff_n /* if not done with cpuvec in a fat binary of in gmp-impl.h*/ +#define mpn_sumdiff_n __MPN(sumdiff_n) +__GMP_DECLSPEC mp_limb_t mpn_sumdiff_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#endif +#ifndef mpn_nsumdiff_n /* if not done with cpuvec in a fat binary of in gmp-impl.h*/ +#define mpn_nsumdiff_n __MPN(nsumdiff_n) +__GMP_DECLSPEC mp_limb_t mpn_nsumdiff_n __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); +#endif +/**************** MPN API for FFT ****************/ +#define mpn_mul_fft_main __MPN(mul_fft_main) +__GMP_DECLSPEC void mpn_mul_fft_main __GMP_PROTO ((mp_ptr r1, mp_srcptr i1, mp_size_t n1, mp_srcptr i2, mp_size_t n2)); +#define mpn_mul_fft __MPN(mul_fft) +__GMP_DECLSPEC int mpn_mul_fft __GMP_PROTO((mp_ptr rp, mp_size_t rn, mp_srcptr ap, mp_size_t an, mp_srcptr bp, mp_size_t bn, int k)); +/**************** mpz inlines ****************/ +/* The following are provided as inlines where possible, but always exist as + library functions too, for binary compatibility. + Within gmp itself this inlining generally isn't relied on, since it + doesn't get done for all compilers, whereas if something is worth + inlining then it's worth arranging always. + There are two styles of inlining here. When the same bit of code is + wanted for the inline as for the library version, then __GMP_FORCE_foo + arranges for that code to be emitted and the __GMP_EXTERN_INLINE + directive suppressed, eg. mpz_fits_uint_p. When a different bit of code + is wanted for the inline than for the library version, then + __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */ +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs) +__GMP_EXTERN_INLINE void +mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size); +} +#endif +#if GMP_NAIL_BITS == 0 +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)); +#else +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \ + || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS))); +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p) +#if ! defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_UINT_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ui_p) +#if ! defined (__GMP_FORCE_mpz_fits_ui_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ui_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, GMP_UI_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p) +#if ! defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_ULONG_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p) +#if ! defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_USHRT_MAX); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui) +#if ! defined (__GMP_FORCE_mpz_get_ui) +__GMP_EXTERN_INLINE +#endif +mpir_ui +mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + mp_ptr __gmp_p = __gmp_z->_mp_d; + mp_size_t __gmp_n = __gmp_z->_mp_size; + mp_limb_t __gmp_l = __gmp_p[0]; + /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings + about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland + C++ 6.0 warnings about condition always true for something like + "__GMP_ULONG_MAX < GMP_NUMB_MASK". */ +#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB) + /* limb==long and no nails, or limb==longlong, one limb is enough */ + return (mpir_ui)(__gmp_n != 0 ? __gmp_l : 0); +#else + /* limb==long and nails, need two limbs when available */ + __gmp_n = __GMP_ABS (__gmp_n); + if (__gmp_n <= 1) + return (mpir_ui)(__gmp_n != 0 ? __gmp_l : 0); + else + return (mpir_ui)(__gmp_l + (__gmp_p[1] << GMP_NUMB_BITS)); +#endif +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn) +#if ! defined (__GMP_FORCE_mpz_getlimbn) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_result = 0; + if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size))) + __gmp_result = __gmp_z->_mp_d[__gmp_n]; + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg) +__GMP_EXTERN_INLINE void +mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = - __gmp_w->_mp_size; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p) +#if ! defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_perfect_square_p (mpz_srcptr __gmp_a) +{ + mp_size_t __gmp_asize; + int __gmp_result; + __gmp_asize = __gmp_a->_mp_size; + __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */ + if (__GMP_LIKELY (__gmp_asize > 0)) + __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount) +#if ! defined (__GMP_FORCE_mpz_popcount) +__GMP_EXTERN_INLINE +#endif +mp_bitcnt_t +mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW +{ + mp_size_t __gmp_usize; + mp_bitcnt_t __gmp_result; + __gmp_usize = __gmp_u->_mp_size; + __gmp_result = (__gmp_usize < 0 ? __GMP_BITCNT_MAX : 0); + if (__GMP_LIKELY (__gmp_usize > 0)) + __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q) +#if ! defined (__GMP_FORCE_mpz_set_q) +__GMP_EXTERN_INLINE +#endif +void +mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u)); +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size) +#if ! defined (__GMP_FORCE_mpz_size) +__GMP_EXTERN_INLINE +#endif +size_t +mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + return __GMP_ABS (__gmp_z->_mp_size); +} +#endif +/**************** mpq inlines ****************/ +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs) +__GMP_EXTERN_INLINE void +mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size); +} +#endif +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg) +__GMP_EXTERN_INLINE void +mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size; +} +#endif +/**************** mpn inlines ****************/ +/* The comments with __GMPN_ADD_1 below apply here too. + The test for FUNCTION returning 0 should predict well. If it's assumed + {yp,ysize} will usually have a random number of bits then the high limb + won't be full and a carry out will occur a good deal less than 50% of the + time. + ysize==0 isn't a documented feature, but is used internally in a few + places. + Producing cout last stops it using up a register during the main part of + the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))" + doesn't seem able to move the true and false legs of the conditional up + to the two places cout is generated. */ +#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x; \ + \ + /* ASSERT ((ysize) >= 0); */ \ + /* ASSERT ((xsize) >= (ysize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \ + \ + __gmp_i = (ysize); \ + if (__gmp_i != 0) \ + { \ + if (FUNCTION (wp, xp, yp, __gmp_i)) \ + { \ + do \ + { \ + if (__gmp_i >= (xsize)) \ + { \ + (cout) = 1; \ + goto __gmp_done; \ + } \ + __gmp_x = (xp)[__gmp_i]; \ + } \ + while (TEST); \ + } \ + } \ + if ((wp) != (xp)) \ + __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \ + (cout) = 0; \ + __gmp_done: \ + ; \ + } while (0) +#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \ + (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0)) +#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \ + (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0)) +/* The use of __gmp_i indexing is designed to ensure a compile time src==dst + remains nice and clear to the compiler, so that __GMPN_COPY_REST can + disappear, and the load/add/store gets a chance to become a + read-modify-write on CISC CPUs. + Alternatives: + Using a pair of pointers instead of indexing would be possible, but gcc + isn't able to recognise compile-time src==dst in that case, even when the + pointers are incremented more or less together. Other compilers would + very likely have similar difficulty. + gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or + similar to detect a compile-time src==dst. This works nicely on gcc + 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems + to be always false, for a pointer p. But the current code form seems + good enough for src==dst anyway. + gcc on x86 as usual doesn't give particularly good flags handling for the + carry/borrow detection. It's tempting to want some multi instruction asm + blocks to help it, and this was tried, but in truth there's only a few + instructions to save and any gain is all too easily lost by register + juggling setting up for the asm. */ +#if GMP_NAIL_BITS == 0 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r; \ + if (CB (__gmp_r, __gmp_x, (v))) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r; \ + ++__gmp_i; \ + if (!CB (__gmp_r, __gmp_x, 1)) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif +#if GMP_NAIL_BITS >= 1 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r & GMP_NUMB_MASK; \ + if (__gmp_r >> GMP_NUMB_BITS != 0) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \ + ++__gmp_i; \ + if (__gmp_r >> GMP_NUMB_BITS == 0) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif +#define __GMPN_ADDCB(r,x,y) ((r) < (y)) +#define __GMPN_SUBCB(r,x,y) ((x) < (y)) +#define __GMPN_ADD_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB) +#define __GMPN_SUB_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB) +/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or + negative. size==0 is allowed. On random data usually only one limb will + need to be examined to get a result, so it's worth having it inline. */ +#define __GMPN_CMP(result, xp, yp, size) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_y; \ + \ + /* ASSERT ((size) >= 0); */ \ + \ + (result) = 0; \ + __gmp_i = (size); \ + while (--__gmp_i >= 0) \ + { \ + __gmp_x = (xp)[__gmp_i]; \ + __gmp_y = (yp)[__gmp_i]; \ + if (__gmp_x != __gmp_y) \ + { \ + /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \ + (result) = (__gmp_x > __gmp_y ? 1 : -1); \ + break; \ + } \ + } \ + } while (0) +#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \ + } while (0) +#endif +/* Copy {src,size} to {dst,size}, starting at "start". This is designed to + keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1, + __GMPN_ADD, etc. */ +#if ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + mp_size_t __gmp_j; \ + /* ASSERT ((size) >= 0); */ \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \ + for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \ + (dst)[__gmp_j] = (src)[__gmp_j]; \ + } while (0) +#endif +/* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use + mpn_copyi if there's a native version, and if we don't mind demanding + binary compatibility for it (on targets which use it). */ +#if ! defined (__GMPN_COPY) +#define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0) +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add) +#if ! defined (__GMP_FORCE_mpn_add) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1) +#if ! defined (__GMP_FORCE_mpn_add_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp) +#if ! defined (__GMP_FORCE_mpn_cmp) +__GMP_EXTERN_INLINE +#endif +int +mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW +{ + int __gmp_result; + __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size); + return __gmp_result; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub) +#if ! defined (__GMP_FORCE_mpn_sub) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1) +#if ! defined (__GMP_FORCE_mpn_sub_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif +#if defined (__cplusplus) +} +#endif +/* Allow faster testing for negative, zero, and positive. */ +#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) +#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) +#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) +/* When using GCC, optimize certain common comparisons. */ +#if defined (__GNUC__) +#define mpz_cmp_ui(Z,UI) \ + (__builtin_constant_p (UI) && (UI) == 0 \ + ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) +#define mpz_cmp_si(Z,SI) \ + (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z) \ + : __builtin_constant_p (SI) && (SI) > 0 \ + ? _mpz_cmp_ui (Z, __GMP_CAST (unsigned long int, SI)) \ + : _mpz_cmp_si (Z,SI)) +#define mpq_cmp_ui(Q,NUI,DUI) \ + (__builtin_constant_p (NUI) && (NUI) == 0 \ + ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI)) +#define mpq_cmp_si(q,n,d) \ + (__builtin_constant_p ((n) >= 0) && (n) >= 0 \ + ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \ + : _mpq_cmp_si (q, n, d)) +#else +#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) +#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) +#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) +#define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d) +#endif +/* Using "&" rather than "&&" means these can come out branch-free. Every + mpz_t has at least one limb allocated, so fetching the low limb is always + allowed. */ +#define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0])) +#define mpz_even_p(z) (! mpz_odd_p (z)) +/**************** C++ routines ****************/ +#ifdef __cplusplus +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr); +#endif +/* Source-level compatibility with GMP 1. */ +#define mpz_mdiv mpz_fdiv_q +#define mpz_mdivmod mpz_fdiv_qr +#define mpz_mmod mpz_fdiv_r +#define mpz_mdiv_ui mpz_fdiv_q_ui +#define mpz_mdivmod_ui(q,r,n,d) \ + (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) +#define mpz_mmod_ui(r,n,d) \ + (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) +#define gmp_randinit(x,y,z) gmp_randinit_lc_2exp_size(x,z) +typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */ +typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */ +#define mpz_div mpz_fdiv_q +#define mpz_divmod mpz_fdiv_qr +#define mpz_div_ui mpz_fdiv_q_ui +#define mpz_divmod_ui mpz_fdiv_qr_ui +#define mpz_div_2exp mpz_fdiv_q_2exp +#define mpz_mod_2exp mpz_fdiv_r_2exp +enum +{ + GMP_ERROR_NONE = 0, + GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, + GMP_ERROR_DIVISION_BY_ZERO = 2, + GMP_ERROR_SQRT_OF_NEGATIVE = 4, + GMP_ERROR_INVALID_ARGUMENT = 8 +}; +/* Major version number is the value of __GNU_MP__ too, above and in mp.h. */ +#define __GNU_MP_VERSION 6 +#define __GNU_MP_VERSION_MINOR 0 +#define __GNU_MP_VERSION_PATCHLEVEL 0 +#define GMP_VERSION "6.0.0" +#define __GNU_MP_RELEASE (__GNU_MP_VERSION * 10000 + __GNU_MP_VERSION_MINOR * 100 + __GNU_MP_VERSION_PATCHLEVEL) +#define __MPIR_VERSION 3 +#define __MPIR_VERSION_MINOR 0 +#define __MPIR_VERSION_PATCHLEVEL 0 +#if defined( _MSC_VER ) +#define _MSC_MPIR_VERSION "3.0.0" +#endif +#define __MPIR_RELEASE (__MPIR_VERSION * 10000 + __MPIR_VERSION_MINOR * 100 + __MPIR_VERSION_PATCHLEVEL) +/* These are for programs like MPFR to use the same CC and CFLAGS as MPIR */ +#if ! defined (__GMP_WITHIN_CONFIGURE) +#endif +#define __GMP_H__ +#endif /* __GMP_H__ */ diff --git a/include/mpir_x64-windows/include/mpirxx.h b/include/mpir_x64-windows/include/mpirxx.h new file mode 100644 index 0000000..f69cb48 --- /dev/null +++ b/include/mpir_x64-windows/include/mpirxx.h @@ -0,0 +1,3675 @@ +/* gmpxx.h -- C++ class wrapper for GMP types. -*- C++ -*- + +Copyright 2001, 2002, 2003, 2006, 2008, 2011, 2012 Free Software Foundation, +Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ + +/* the C++ compiler must implement the following features: + - member templates + - partial specialization of templates + - namespace support + for g++, this means version 2.91 or higher + for other compilers, I don't know */ +#ifdef __GNUC__ +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 91) +#error mpirxx.h requires g++ version 2.91 (egcs 1.1.2) or higher +#endif +#endif +#ifndef __GMP_PLUSPLUS__ +#define __GMP_PLUSPLUS__ + +#include /* for size_t */ + +#include + +#include /* for strlen */ +#include /* numeric_limits */ +#include +#include +#include +#include +#include /* swap */ +#include + +#if defined( _MSC_VER ) && _MSC_VER >= 1700 +# define MSC_CXX_11 1 +#elif defined( __INTEL_COMPILER ) && __INTEL_COMPILER > 1310 +# define MSC_CXX_11 1 +#elif defined( __ICL ) && __ICL > 1310 +# define MSC_CXX_11 1 +#endif + +#if defined(LLONG_MAX) && defined(LONG_MAX) +#if LLONG_MAX != LONG_MAX +#define MPIRXX_HAVE_LLONG 1 +#endif +#endif + +/* check availability of stdint.h -- note we do not include this ourselves */ +#if defined(INTMAX_MAX) +# if defined(LONG_MAX) && defined(INTMAX_MAX) && INTMAX_MAX != LONG_MAX && (INTMAX_MAX != LLONG_MAX || !defined(MPIRXX_HAVE_LLONG)) +# define MPIRXX_INTMAX_T 1 +# endif +# if defined(ULONG_MAX) && defined(UINTMAX_MAX) && UINTMAX_MAX != ULONG_MAX && (UINTMAX_MAX != ULLONG_MAX || !defined(MPIRXX_HAVE_LLONG)) +# define MPIRXX_UINTMAX_T 1 +# endif +#endif + +// wrapper for gcc's __builtin_constant_p +// __builtin_constant_p has been in gcc since forever, +// but g++-3.4 miscompiles it. +#if __GMP_GNUC_PREREQ(4, 2) +#define __GMPXX_CONSTANT(X) __builtin_constant_p(X) +#else +#define __GMPXX_CONSTANT(X) false +#endif + +// Use C++11 features +#ifndef __GMPXX_USE_CXX11 +#if __cplusplus >= 201103L +#define __GMPXX_USE_CXX11 1 +#else +#define __GMPXX_USE_CXX11 0 +#endif +#endif + +#if __GMPXX_USE_CXX11 +#define __GMPXX_NOEXCEPT noexcept +#include // for common_type +#else +#define __GMPXX_NOEXCEPT +#endif + +// Max allocations for plain types when converted to mpz_t +#define __GMPZ_DBL_LIMBS (2 + DBL_MAX_EXP / GMP_NUMB_BITS) + +#if GMP_NAIL_BITS != 0 && ! defined _LONG_LONG_LIMB +#define __GMPZ_ULI_LIMBS 2 +#else +#define __GMPZ_ULI_LIMBS 1 +#endif + +inline void __mpz_set_ui_safe(mpz_ptr p, mpir_ui l) +{ + p->_mp_size = (l != 0); + p->_mp_d[0] = l & GMP_NUMB_MASK; +#if __GMPZ_ULI_LIMBS > 1 + l >>= GMP_NUMB_BITS; + p->_mp_d[1] = l; + p->_mp_size += (l != 0); +#endif +} + +inline void __mpz_set_si_safe(mpz_ptr p, mpir_si l) +{ + if(l < 0) + { + __mpz_set_ui_safe(p, static_cast(-l)); + mpz_neg(p, p); + } + else + __mpz_set_ui_safe(p, l); + // Note: we know the high bit of l is 0 so we could do slightly better +} + +// Fake temporary variables +#define __GMPXX_TMPZ_UI \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS]; \ + temp->_mp_d = limbs; \ + __mpz_set_ui_safe (temp, l) +#define __GMPXX_TMPZ_SI \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS]; \ + temp->_mp_d = limbs; \ + __mpz_set_si_safe (temp, l) +#define __GMPXX_TMPZ_D \ + mpz_t temp; \ + mp_limb_t limbs[__GMPZ_DBL_LIMBS]; \ + temp->_mp_d = limbs; \ + temp->_mp_alloc = __GMPZ_DBL_LIMBS; \ + mpz_set_d (temp, d) + +#define __GMPXX_TMPQ_UI \ + mpq_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS+1]; \ + mpq_numref(temp)->_mp_d = limbs; \ + __mpz_set_ui_safe (mpq_numref(temp), l); \ + mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS; \ + mpq_denref(temp)->_mp_size = 1; \ + mpq_denref(temp)->_mp_d[0] = 1 +#define __GMPXX_TMPQ_SI \ + mpq_t temp; \ + mp_limb_t limbs[__GMPZ_ULI_LIMBS+1]; \ + mpq_numref(temp)->_mp_d = limbs; \ + __mpz_set_si_safe (mpq_numref(temp), l); \ + mpq_denref(temp)->_mp_d = limbs + __GMPZ_ULI_LIMBS; \ + mpq_denref(temp)->_mp_size = 1; \ + mpq_denref(temp)->_mp_d[0] = 1 + +inline mpir_ui __gmpxx_abs_ui (mpir_si l) +{ + return l >= 0 ? static_cast(l) + : static_cast(-l); +} + +/**************** Function objects ****************/ +/* Any evaluation of a __gmp_expr ends up calling one of these functions + all intermediate functions being inline, the evaluation should optimize + to a direct call to the relevant function, thus yielding no overhead + over the C interface. */ + +struct __gmp_unary_plus +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_set(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_set(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_set(f, g); } +}; + +struct __gmp_unary_minus +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_neg(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_neg(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_neg(f, g); } +}; + +struct __gmp_unary_com +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_com(z, w); } +}; + +struct __gmp_binary_plus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_add(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + // Ideally, those checks should happen earlier so that the tree + // generated for a+0+b would just be sum(a,b). + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (z != w) mpz_set(z, w); + } + else + mpz_add_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + mpz_sub_ui(z, w, static_cast(-l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_add (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_add(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (q != r) mpq_set(q, r); + } + else + { + if (q == r) + mpz_addmul_ui(mpq_numref(q), mpq_denref(q), l); + else + { + mpz_mul_ui(mpq_numref(q), mpq_denref(r), l); + mpz_add(mpq_numref(q), mpq_numref(q), mpq_numref(r)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); } + static inline void eval(mpq_ptr q, mpq_srcptr r, mpir_si l); + // defined after __gmp_binary_minus + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_add(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { eval(q, r, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z) + { + if (q == r) + mpz_addmul(mpq_numref(q), mpq_denref(q), z); + else + { + mpz_mul(mpq_numref(q), mpq_denref(r), z); + mpz_add(mpq_numref(q), mpq_numref(q), mpq_numref(r)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r) + { eval(q, r, z); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_add(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_add_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_add_ui(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_add_ui(f, g, l); + else + mpf_sub_ui(f, g, static_cast(-l)); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_add(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_binary_minus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_sub(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (z != w) mpz_set(z, w); + } + else + mpz_sub_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + mpz_neg(z, w); + } + else + mpz_ui_sub(z, l, w); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + mpz_add_ui(z, w, static_cast(-l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (l >= 0) + eval(z, static_cast(l), w); + else + { + mpz_add_ui(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_sub (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_sub (z, temp, w); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_sub(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { + if (__GMPXX_CONSTANT(l) && l == 0) + { + if (q != r) mpq_set(q, r); + } + else + { + if (q == r) + mpz_submul_ui(mpq_numref(q), mpq_denref(q), l); + else + { + mpz_mul_ui(mpq_numref(q), mpq_denref(r), l); + mpz_sub(mpq_numref(q), mpq_numref(r), mpq_numref(q)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); mpq_neg(q, q); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + __gmp_binary_plus::eval(q, r, static_cast(-l)); + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); mpq_neg(q, q); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_sub(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_sub(q, temp, r); + mpq_clear(temp); + } + + static void eval(mpq_ptr q, mpq_srcptr r, mpz_srcptr z) + { + if (q == r) + mpz_submul(mpq_numref(q), mpq_denref(q), z); + else + { + mpz_mul(mpq_numref(q), mpq_denref(r), z); + mpz_sub(mpq_numref(q), mpq_numref(r), mpq_numref(q)); + mpz_set(mpq_denref(q), mpq_denref(r)); + } + } + static void eval(mpq_ptr q, mpz_srcptr z, mpq_srcptr r) + { eval(q, r, z); mpq_neg(q, q); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_sub(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_sub_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_ui_sub(f, l, g); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_sub_ui(f, g, l); + else + mpf_add_ui(f, g, static_cast(-l)); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { + if (l >= 0) + mpf_sub_ui(f, g, l); + else + mpf_add_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_sub(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_sub(f, temp, g); + mpf_clear(temp); + } +}; + +// defined here so it can reference __gmp_binary_minus +inline void +__gmp_binary_plus::eval(mpq_ptr q, mpq_srcptr r, mpir_si l) +{ + if (l >= 0) + eval(q, r, static_cast(l)); + else + __gmp_binary_minus::eval(q, r, static_cast(-l)); +} + +struct __gmp_binary_lshift +{ + static void eval(mpz_ptr z, mpz_srcptr w, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (z != w) mpz_set(z, w); + } + else + mpz_mul_2exp(z, w, l); + } + static void eval(mpq_ptr q, mpq_srcptr r, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (q != r) mpq_set(q, r); + } + else + mpq_mul_2exp(q, r, l); + } + static void eval(mpf_ptr f, mpf_srcptr g, mp_bitcnt_t l) + { mpf_mul_2exp(f, g, l); } +}; + +struct __gmp_binary_rshift +{ + static void eval(mpz_ptr z, mpz_srcptr w, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (z != w) mpz_set(z, w); + } + else + mpz_fdiv_q_2exp(z, w, l); + } + static void eval(mpq_ptr q, mpq_srcptr r, mp_bitcnt_t l) + { + if (__GMPXX_CONSTANT(l) && (l == 0)) + { + if (q != r) mpq_set(q, r); + } + else + mpq_div_2exp(q, r, l); + } + static void eval(mpf_ptr f, mpf_srcptr g, mp_bitcnt_t l) + { mpf_div_2exp(f, g, l); } +}; + +struct __gmp_binary_multiplies +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_mul(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { +// gcc-3.3 doesn't have __builtin_ctzl. Don't bother optimizing for old gcc. +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0) + { + if (l == 0) + { + z->_mp_size = 0; + } + else + { + __gmp_binary_lshift::eval(z, w, __builtin_ctzl(l)); + } + } + else +#endif + mpz_mul_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + { + eval(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + else + mpz_mul_si (z, w, l); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_mul (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_mul(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0) + { + if (l == 0) + { + mpq_set_ui(q, 0, 1); + } + else + { + __gmp_binary_lshift::eval(q, r, __builtin_ctzl(l)); + } + } + else +#endif + { + __GMPXX_TMPQ_UI; + mpq_mul (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + { + eval(q, r, static_cast(-l)); + mpq_neg(q, q); + } + } + else + { + __GMPXX_TMPQ_SI; + mpq_mul (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { eval(q, r, l); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_mul(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { eval(q, r, d); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_mul(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_mul_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_mul_ui(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_mul_ui(f, g, l); + else + { + mpf_mul_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_mul(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_binary_divides +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_tdiv_q(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + // Don't optimize division by 0... + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0 && l != 0) + { + if (l == 1) + { + if (z != w) mpz_set(z, w); + } + else + mpz_tdiv_q_2exp(z, w, __builtin_ctzl(l)); + // warning: do not use rshift (fdiv) + } + else +#endif + mpz_tdiv_q_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (mpz_sgn(w) >= 0) + { + if (mpz_fits_ui_p(w)) + mpz_set_ui(z, l / mpz_get_ui(w)); + else + mpz_set_ui(z, 0); + } + else + { + mpz_neg(z, w); + if (mpz_fits_ui_p(z)) + { + mpz_set_ui(z, l / mpz_get_ui(z)); + mpz_neg(z, z); + } + else + mpz_set_ui(z, 0); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + if (l >= 0) + eval(z, w, static_cast(l)); + else + { + eval(z, w, static_cast(-l)); + mpz_neg(z, z); + } + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (mpz_fits_si_p(w)) + mpz_set_si(z, l / mpz_get_si(w)); + else + { + /* if w is bigger than a long then the quotient must be zero, unless + l==LONG_MIN and w==-LONG_MIN in which case the quotient is -1 */ + mpz_set_si (z, (mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? -1 : 0)); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_tdiv_q (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_tdiv_q (z, temp, w); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpq_srcptr s) + { mpq_div(q, r, s); } + + static void eval(mpq_ptr q, mpq_srcptr r, mpir_ui l) + { +#if __GMP_GNUC_PREREQ(3, 4) + if (__GMPXX_CONSTANT(l) && (l & (l-1)) == 0 && l != 0) + __gmp_binary_rshift::eval(q, r, __builtin_ctzl(l)); + else +#endif + { + __GMPXX_TMPQ_UI; + mpq_div (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_ui l, mpq_srcptr r) + { __GMPXX_TMPQ_UI; mpq_div (q, temp, r); } + static void eval(mpq_ptr q, mpq_srcptr r, mpir_si l) + { + if (__GMPXX_CONSTANT(l)) + { + if (l >= 0) + eval(q, r, static_cast(l)); + else + { + eval(q, r, static_cast(-l)); + mpq_neg(q, q); + } + } + else + { + __GMPXX_TMPQ_SI; + mpq_div (q, r, temp); + } + } + static void eval(mpq_ptr q, mpir_si l, mpq_srcptr r) + { __GMPXX_TMPQ_SI; mpq_div (q, temp, r); } + static void eval(mpq_ptr q, mpq_srcptr r, double d) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_div(q, r, temp); + mpq_clear(temp); + } + static void eval(mpq_ptr q, double d, mpq_srcptr r) + { + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + mpq_div(q, temp, r); + mpq_clear(temp); + } + + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { mpf_div(f, g, h); } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { mpf_div_ui(f, g, l); } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { mpf_ui_div(f, l, g); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + if (l >= 0) + mpf_div_ui(f, g, l); + else + { + mpf_div_ui(f, g, static_cast(-l)); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { + if (l >= 0) + mpf_ui_div(f, l, g); + else + { + mpf_ui_div(f, static_cast(-l), g); + mpf_neg(f, f); + } + } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_div(f, g, temp); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { + mpf_t temp; + mpf_init2(temp, 8*sizeof(double)); + mpf_set_d(temp, d); + mpf_div(f, temp, g); + mpf_clear(temp); + } +}; + +struct __gmp_binary_modulus +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_tdiv_r(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { mpz_tdiv_r_ui(z, w, l); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + if (mpz_sgn(w) >= 0) + { + if (mpz_fits_ui_p(w)) + mpz_set_ui(z, l % mpz_get_ui(w)); + else + mpz_set_ui(z, l); + } + else + { + mpz_neg(z, w); + if (mpz_fits_ui_p(z)) + mpz_set_ui(z, l % mpz_get_ui(z)); + else + mpz_set_ui(z, l); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + mpz_tdiv_r_ui (z, w, (l >= 0 ? l : -l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + if (mpz_fits_si_p(w)) + mpz_set_si(z, l % mpz_get_si(w)); + else + { + /* if w is bigger than a long then the remainder is l unchanged, + unless l==LONG_MIN and w==-LONG_MIN in which case it's 0 */ + mpz_set_si (z, mpz_cmpabs_ui (w, (l >= 0 ? l : -l)) == 0 ? 0 : l); + } + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_tdiv_r (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { __GMPXX_TMPZ_D; mpz_tdiv_r (z, temp, w); } +}; + +struct __gmp_binary_and +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_and(z, w, v); } + + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_and (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_ior +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_ior(z, w, v); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_ior (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_xor +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { mpz_xor(z, w, v); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { __GMPXX_TMPZ_UI; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { __GMPXX_TMPZ_SI; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { eval(z, w, l); } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { __GMPXX_TMPZ_D; mpz_xor (z, w, temp); } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { eval(z, w, d); } +}; + +struct __gmp_binary_equal +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) == 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) == 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) == 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) == 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) == 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) == 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) == 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) + { return mpq_equal(q, r) != 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) == 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) == 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) == 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) == 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_equal(q, temp) != 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + return eval(q, d); + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) == 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) == 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) == 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) == 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) == 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) == 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) == 0; } +}; + +struct __gmp_binary_less +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) < 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) < 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) > 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) < 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) > 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) < 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) > 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) < 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) < 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) > 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) < 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) > 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(q, temp) < 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(temp, q) < 0); + mpq_clear(temp); + return b; + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) < 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) < 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) > 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) < 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) > 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) < 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) > 0; } +}; + +struct __gmp_binary_greater +{ + static bool eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w) > 0; } + + static bool eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l) > 0; } + static bool eval(mpir_ui l, mpz_srcptr z) + { return mpz_cmp_ui(z, l) < 0; } + static bool eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l) > 0; } + static bool eval(mpir_si l, mpz_srcptr z) + { return mpz_cmp_si(z, l) < 0; } + static bool eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d) > 0; } + static bool eval(double d, mpz_srcptr z) + { return mpz_cmp_d(z, d) < 0; } + + static bool eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r) > 0; } + + static bool eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1) > 0; } + static bool eval(mpir_ui l, mpq_srcptr q) + { return mpq_cmp_ui(q, l, 1) < 0; } + static bool eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1) > 0; } + static bool eval(mpir_si l, mpq_srcptr q) + { return mpq_cmp_si(q, l, 1) < 0; } + static bool eval(mpq_srcptr q, double d) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(q, temp) > 0); + mpq_clear(temp); + return b; + } + static bool eval(double d, mpq_srcptr q) + { + bool b; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + b = (mpq_cmp(temp, q) > 0); + mpq_clear(temp); + return b; + } + + static bool eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g) > 0; } + + static bool eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l) > 0; } + static bool eval(mpir_ui l, mpf_srcptr f) + { return mpf_cmp_ui(f, l) < 0; } + static bool eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l) > 0; } + static bool eval(mpir_si l, mpf_srcptr f) + { return mpf_cmp_si(f, l) < 0; } + static bool eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d) > 0; } + static bool eval(double d, mpf_srcptr f) + { return mpf_cmp_d(f, d) < 0; } +}; + +struct __gmp_unary_increment +{ + static void eval(mpz_ptr z) { mpz_add_ui(z, z, 1); } + static void eval(mpq_ptr q) + { mpz_add(mpq_numref(q), mpq_numref(q), mpq_denref(q)); } + static void eval(mpf_ptr f) { mpf_add_ui(f, f, 1); } +}; + +struct __gmp_unary_decrement +{ + static void eval(mpz_ptr z) { mpz_sub_ui(z, z, 1); } + static void eval(mpq_ptr q) + { mpz_sub(mpq_numref(q), mpq_numref(q), mpq_denref(q)); } + static void eval(mpf_ptr f) { mpf_sub_ui(f, f, 1); } +}; + +struct __gmp_abs_function +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_abs(z, w); } + static void eval(mpq_ptr q, mpq_srcptr r) { mpq_abs(q, r); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_abs(f, g); } +}; + +struct __gmp_trunc_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_trunc(f, g); } +}; + +struct __gmp_floor_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_floor(f, g); } +}; + +struct __gmp_ceil_function +{ + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_ceil(f, g); } +}; + +struct __gmp_sqrt_function +{ + static void eval(mpz_ptr z, mpz_srcptr w) { mpz_sqrt(z, w); } + static void eval(mpf_ptr f, mpf_srcptr g) { mpf_sqrt(f, g); } +}; + +struct __gmp_hypot_function +{ + static void eval(mpf_ptr f, mpf_srcptr g, mpf_srcptr h) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_mul(f, h, h); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + + static void eval(mpf_ptr f, mpf_srcptr g, mpir_ui l) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_ui(f, l); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, mpir_ui l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, mpir_si l) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_si(f, l); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, mpir_si l, mpf_srcptr g) + { eval(f, g, l); } + static void eval(mpf_ptr f, mpf_srcptr g, double d) + { + mpf_t temp; + mpf_init2(temp, mpf_get_prec(f)); + mpf_mul(temp, g, g); + mpf_set_d(f, d); + mpf_mul(f, f, f); + mpf_add(f, f, temp); + mpf_sqrt(f, f); + mpf_clear(temp); + } + static void eval(mpf_ptr f, double d, mpf_srcptr g) + { eval(f, g, d); } +}; + +struct __gmp_sgn_function +{ + static int eval(mpz_srcptr z) { return mpz_sgn(z); } + static int eval(mpq_srcptr q) { return mpq_sgn(q); } + static int eval(mpf_srcptr f) { return mpf_sgn(f); } +}; + +struct __gmp_gcd_function +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { + mpz_gcd(z, w, v); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + mpz_gcd_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + eval(z, w, __gmpxx_abs_ui(l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { + __GMPXX_TMPZ_D; mpz_gcd(z, w, temp); + } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { + eval(z, w, d); + } +}; + +struct __gmp_lcm_function +{ + static void eval(mpz_ptr z, mpz_srcptr w, mpz_srcptr v) + { + mpz_lcm(z, w, v); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_ui l) + { + mpz_lcm_ui(z, w, l); + } + static void eval(mpz_ptr z, mpir_ui l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, mpir_si l) + { + eval(z, w, __gmpxx_abs_ui(l)); + } + static void eval(mpz_ptr z, mpir_si l, mpz_srcptr w) + { + eval(z, w, l); + } + static void eval(mpz_ptr z, mpz_srcptr w, double d) + { + __GMPXX_TMPZ_D; mpz_lcm(z, w, temp); + } + static void eval(mpz_ptr z, double d, mpz_srcptr w) + { + eval(z, w, d); + } +}; + +struct __gmp_cmp_function +{ + static int eval(mpz_srcptr z, mpz_srcptr w) { return mpz_cmp(z, w); } + + static int eval(mpz_srcptr z, mpir_ui l) + { return mpz_cmp_ui(z, l); } + static int eval(mpir_ui l, mpz_srcptr z) + { return -mpz_cmp_ui(z, l); } + static int eval(mpz_srcptr z, mpir_si l) + { return mpz_cmp_si(z, l); } + static int eval(mpir_si l, mpz_srcptr z) + { return -mpz_cmp_si(z, l); } + static int eval(mpz_srcptr z, double d) + { return mpz_cmp_d(z, d); } + static int eval(double d, mpz_srcptr z) + { return -mpz_cmp_d(z, d); } + + static int eval(mpq_srcptr q, mpq_srcptr r) { return mpq_cmp(q, r); } + + static int eval(mpq_srcptr q, mpir_ui l) + { return mpq_cmp_ui(q, l, 1); } + static int eval(mpir_ui l, mpq_srcptr q) + { return -mpq_cmp_ui(q, l, 1); } + static int eval(mpq_srcptr q, mpir_si l) + { return mpq_cmp_si(q, l, 1); } + static int eval(mpir_si l, mpq_srcptr q) + { return -mpq_cmp_si(q, l, 1); } + static int eval(mpq_srcptr q, double d) + { + int i; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + i = mpq_cmp(q, temp); + mpq_clear(temp); + return i; + } + static int eval(double d, mpq_srcptr q) + { + int i; + mpq_t temp; + mpq_init(temp); + mpq_set_d(temp, d); + i = mpq_cmp(temp, q); + mpq_clear(temp); + return i; + } + + static int eval(mpf_srcptr f, mpf_srcptr g) { return mpf_cmp(f, g); } + + static int eval(mpf_srcptr f, mpir_ui l) + { return mpf_cmp_ui(f, l); } + static int eval(mpir_ui l, mpf_srcptr f) + { return -mpf_cmp_ui(f, l); } + static int eval(mpf_srcptr f, mpir_si l) + { return mpf_cmp_si(f, l); } + static int eval(mpir_si l, mpf_srcptr f) + { return -mpf_cmp_si(f, l); } + static int eval(mpf_srcptr f, double d) + { return mpf_cmp_d(f, d); } + static int eval(double d, mpf_srcptr f) + { return -mpf_cmp_d(f, d); } +}; + +struct __gmp_rand_function +{ + static void eval(mpz_ptr z, gmp_randstate_t s, mp_bitcnt_t l) + { mpz_urandomb(z, s, l); } + static void eval(mpz_ptr z, gmp_randstate_t s, mpz_srcptr w) + { mpz_urandomm(z, s, w); } + static void eval(mpf_ptr f, gmp_randstate_t s, mp_bitcnt_t prec) + { mpf_urandomb(f, s, prec); } +}; + + +/**************** Auxiliary classes ****************/ + +/* this is much the same as gmp_allocated_string in gmp-impl.h + since gmp-impl.h is not publicly available, I redefine it here + I use a different name to avoid possible clashes */ + +extern "C" { + typedef void (*__gmp_freefunc_t) (void *, size_t); +} +struct __gmp_alloc_cstring +{ + char *str; + __gmp_alloc_cstring(char *s) { str = s; } + ~__gmp_alloc_cstring() + { + __gmp_freefunc_t freefunc; + mp_get_memory_functions (NULL, NULL, &freefunc); + (*freefunc) (str, std::strlen(str)+1); + } +}; + + +// general expression template class +template +class __gmp_expr; + + +// templates for resolving expression types +template +struct __gmp_resolve_ref +{ + typedef T ref_type; +}; + +template +struct __gmp_resolve_ref<__gmp_expr > +{ + typedef const __gmp_expr & ref_type; +}; + + +template +struct __gmp_resolve_expr; + +template <> +struct __gmp_resolve_expr +{ + typedef mpz_t value_type; + typedef mpz_ptr ptr_type; + typedef mpz_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; + typedef mpq_ptr ptr_type; + typedef mpq_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; + typedef mpf_ptr ptr_type; + typedef mpf_srcptr srcptr_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpq_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +template <> +struct __gmp_resolve_expr +{ + typedef mpf_t value_type; +}; + +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) +namespace std { + template + struct common_type <__gmp_expr, __gmp_expr > + { + private: + typedef typename __gmp_resolve_expr::value_type X; + public: + typedef __gmp_expr type; + }; + + template + struct common_type <__gmp_expr, __gmp_expr > + { + typedef __gmp_expr type; + }; + +#define __GMPXX_DECLARE_COMMON_TYPE(typ) \ + template \ + struct common_type <__gmp_expr, typ > \ + { \ + typedef __gmp_expr type; \ + }; \ + \ + template \ + struct common_type > \ + { \ + typedef __gmp_expr type; \ + } + + __GMPXX_DECLARE_COMMON_TYPE(signed char); + __GMPXX_DECLARE_COMMON_TYPE(unsigned char); + __GMPXX_DECLARE_COMMON_TYPE(signed int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned int); + __GMPXX_DECLARE_COMMON_TYPE(signed short int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned short int); + __GMPXX_DECLARE_COMMON_TYPE(signed long int); + __GMPXX_DECLARE_COMMON_TYPE(unsigned long int); + __GMPXX_DECLARE_COMMON_TYPE(float); + __GMPXX_DECLARE_COMMON_TYPE(double); +#undef __GMPXX_DECLARE_COMMON_TYPE +} +#endif + +// classes for evaluating unary and binary expressions +template +struct __gmp_unary_expr +{ + const T &val; + + __gmp_unary_expr(const T &v) : val(v) { } +private: + __gmp_unary_expr(); +}; + +template +struct __gmp_binary_expr +{ + typename __gmp_resolve_ref::ref_type val1; + typename __gmp_resolve_ref::ref_type val2; + + __gmp_binary_expr(const T &v1, const U &v2) : val1(v1), val2(v2) { } +private: + __gmp_binary_expr(); +}; + + + +/**************** Macros for in-class declarations ****************/ +/* This is just repetitive code that is easier to maintain if it's written + only once */ + +#define __GMPP_DECLARE_COMPOUND_OPERATOR(fun) \ + template \ + __gmp_expr & fun(const __gmp_expr &); +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DECLARE_COMPOUND_OPERATOR(fun) \ + __gmp_expr & fun(signed char); \ + __gmp_expr & fun(unsigned char); \ + __gmp_expr & fun(signed int); \ + __gmp_expr & fun(unsigned int); \ + __gmp_expr & fun(signed short int); \ + __gmp_expr & fun(unsigned short int); \ + __gmp_expr & fun(signed long int); \ + __gmp_expr & fun(unsigned long int); \ + __gmp_expr & fun(signed long long int); \ + __gmp_expr & fun(unsigned long long int); \ + __gmp_expr & fun(float); \ + __gmp_expr & fun(double); \ + __gmp_expr & fun(long double); +#else +#define __GMPN_DECLARE_COMPOUND_OPERATOR(fun) \ + __gmp_expr & fun(signed char); \ + __gmp_expr & fun(unsigned char); \ + __gmp_expr & fun(signed int); \ + __gmp_expr & fun(unsigned int); \ + __gmp_expr & fun(signed short int); \ + __gmp_expr & fun(unsigned short int); \ + __gmp_expr & fun(signed long int); \ + __gmp_expr & fun(unsigned long int); \ + __gmp_expr & fun(float); \ + __gmp_expr & fun(double); \ + __gmp_expr & fun(long double); +#endif + +#define __GMP_DECLARE_COMPOUND_OPERATOR(fun) \ +__GMPP_DECLARE_COMPOUND_OPERATOR(fun) \ +__GMPN_DECLARE_COMPOUND_OPERATOR(fun) + +#define __GMP_DECLARE_COMPOUND_OPERATOR_UI(fun) \ + __gmp_expr & fun(mp_bitcnt_t); + +#define __GMP_DECLARE_INCREMENT_OPERATOR(fun) \ + inline __gmp_expr & fun(); \ + inline __gmp_expr fun(int); + + +/**************** mpz_class -- wrapper for mpz_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpz_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } + + // constructors and destructor + __gmp_expr() { mpz_init(mp); } + + __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&z) + { *mp = *z.mp; mpz_init(z.mp); } +#endif + template + __gmp_expr(const __gmp_expr &expr) + { mpz_init(mp); __gmp_set_expr(mp, expr); } + template + explicit __gmp_expr(const __gmp_expr &expr) + { mpz_init(mp); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpz_init_set_si(mp, c); } + __gmp_expr(unsigned char c) { mpz_init_set_ui(mp, c); } + + __gmp_expr(signed int i) { mpz_init_set_si(mp, i); } + __gmp_expr(unsigned int i) { mpz_init_set_ui(mp, i); } + + __gmp_expr(signed short int s) { mpz_init_set_si(mp, s); } + __gmp_expr(unsigned short int s) { mpz_init_set_ui(mp, s); } + + __gmp_expr(signed long int l) { mpz_init_set_si(mp, l); } + __gmp_expr(unsigned long int l) { mpz_init_set_ui(mp, l); } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int l) { mpz_init_set_si(mp, l); } + __gmp_expr(unsigned long long int l) { mpz_init_set_ui(mp, l); } +#endif + +#ifdef MPIRXX_INTMAX_T + __gmp_expr(intmax_t l) { mpz_init_set_sx(mp, l); } +#endif + +#ifdef MPIRXX_UINTMAX_T + __gmp_expr(uintmax_t l) { mpz_init_set_ux(mp, l); } +#endif + + __gmp_expr(float f) { mpz_init_set_d(mp, f); } + __gmp_expr(double d) { mpz_init_set_d(mp, d); } + // __gmp_expr(long double ld) { mpz_init_set_d(mp, ld); } + + explicit __gmp_expr(const char *s, int base = 0) + { + if (mpz_init_set_str (mp, s, base) != 0) + { + mpz_clear (mp); + throw std::invalid_argument ("mpz_set_str"); + } + } + explicit __gmp_expr(const std::string &s, int base = 0) + { + if (mpz_init_set_str(mp, s.c_str(), base) != 0) + { + mpz_clear (mp); + throw std::invalid_argument ("mpz_set_str"); + } + } + + explicit __gmp_expr(mpz_srcptr z) { mpz_init_set(mp, z); } + + ~__gmp_expr() { mpz_clear(mp); } + + void swap(__gmp_expr& z) __GMPXX_NOEXCEPT { std::swap(*mp, *z.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &z) + { mpz_set(mp, z.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&z) __GMPXX_NOEXCEPT + { swap(z); return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + +__gmp_expr & operator=(signed char c) { mpz_set_si(mp, c); return *this; } +__gmp_expr & operator=(unsigned char c) { mpz_set_ui(mp, c); return *this; } + +__gmp_expr & operator=(signed int i) { mpz_set_si(mp, i); return *this; } +__gmp_expr & operator=(unsigned int i) { mpz_set_ui(mp, i); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpz_set_si(mp, s); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpz_set_ui(mp, s); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpz_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpz_set_ui(mp, l); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int i) { mpz_set_si(mp, i); return *this; } + __gmp_expr & operator=(unsigned long long int i) { mpz_set_ui(mp, i); return *this; } +#endif + +#ifdef MPIRXX_INTMAX_T + __gmp_expr & operator=(intmax_t i) { mpz_set_sx(mp, i); return *this; } +#endif + +#ifdef MPIRXX_UINTMAX_T + __gmp_expr & operator=(uintmax_t i) { mpz_set_ux(mp, i); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpz_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpz_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpz_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpz_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpz_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpz_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpz_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpz_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpz_set_str(mp, s.c_str(), base); } + std::string get_str(int base = 10) const + { + __gmp_alloc_cstring temp(mpz_get_str(0, base, mp)); + return std::string(temp.str); + } + + // conversion functions + mpz_srcptr __get_mp() const { return mp; } + mpz_ptr __get_mp() { return mp; } + mpz_srcptr get_mpz_t() const { return mp; } + mpz_ptr get_mpz_t() { return mp; } + + mpir_si get_si() const { return mpz_get_si(mp); } + mpir_ui get_ui() const { return mpz_get_ui(mp); } + +#ifdef MPIRXX_INTMAX_T + intmax_t get_sx() const { return mpz_get_sx(mp); } +#endif +#ifdef MPIRXX_UINTMAX_T + uintmax_t get_ux() const { return mpz_get_ux(mp); } +#endif + + double get_d() const { return mpz_get_d(mp); } + + // bool fits_schar_p() const { return mpz_fits_schar_p(mp); } + // bool fits_uchar_p() const { return mpz_fits_uchar_p(mp); } + bool fits_sint_p() const { return mpz_fits_sint_p(mp) != 0; } + bool fits_uint_p() const { return mpz_fits_uint_p(mp) != 0; } + bool fits_si_p() const { return mpz_fits_si_p(mp) != 0; } + bool fits_ui_p() const { return mpz_fits_ui_p(mp) != 0; } + bool fits_sshort_p() const { return mpz_fits_sshort_p(mp) != 0; } + bool fits_ushort_p() const { return mpz_fits_ushort_p(mp) != 0; } + bool fits_slong_p() const { return mpz_fits_slong_p(mp) != 0; } + bool fits_ulong_p() const { return mpz_fits_ulong_p(mp) != 0; } + // bool fits_float_p() const { return mpz_fits_float_p(mp) != 0; } + // bool fits_double_p() const { return mpz_fits_double_p(mp) != 0; } + // bool fits_ldouble_p() const { return mpz_fits_ldouble_p(mp) != 0; } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mp->_mp_size != 0; } +#endif + + // member operators + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator%=) + + __GMP_DECLARE_COMPOUND_OPERATOR(operator&=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator|=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator^=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpz_class; + + +/**************** mpq_class -- wrapper for mpq_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpq_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } + void canonicalize() { mpq_canonicalize(mp); } + + // constructors and destructor + __gmp_expr() { mpq_init(mp); } + + __gmp_expr(const __gmp_expr &q) + { + mpz_init_set(mpq_numref(mp), mpq_numref(q.mp)); + mpz_init_set(mpq_denref(mp), mpq_denref(q.mp)); + } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&q) + { *mp = *q.mp; mpq_init(q.mp); } +#endif + template + __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + template + __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + template + explicit __gmp_expr(const __gmp_expr &expr) + { mpq_init(mp); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpq_init(mp); mpq_set_si(mp, c, 1); } + __gmp_expr(unsigned char c) { mpq_init(mp); mpq_set_ui(mp, c, 1); } + + __gmp_expr(signed int i) { mpq_init(mp); mpq_set_si(mp, i, 1); } + __gmp_expr(unsigned int i) { mpq_init(mp); mpq_set_ui(mp, i, 1); } + + __gmp_expr(signed short int s) { mpq_init(mp); mpq_set_si(mp, s, 1); } + __gmp_expr(unsigned short int s) { mpq_init(mp); mpq_set_ui(mp, s, 1); } + + __gmp_expr(signed long int l) { mpq_init(mp); mpq_set_si(mp, l, 1); } + __gmp_expr(unsigned long int l) { mpq_init(mp); mpq_set_ui(mp, l, 1); } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int l) { mpq_init(mp); mpq_set_si(mp, l, 1); } + __gmp_expr(unsigned long long int l) { mpq_init(mp); mpq_set_ui(mp, l, 1); } +#endif + + __gmp_expr(float f) { mpq_init(mp); mpq_set_d(mp, f); } + __gmp_expr(double d) { mpq_init(mp); mpq_set_d(mp, d); } + // __gmp_expr(long double ld) { mpq_init(mp); mpq_set_ld(mp, ld); } + + explicit __gmp_expr(const char *s, int base = 0) + { + mpq_init (mp); + // If s is the literal 0, we meant to call another constructor. + // If s just happens to evaluate to 0, we would crash, so whatever. + if (s == 0) + { + // Don't turn mpq_class(0,0) into 0 + mpz_set_si(mpq_denref(mp), base); + } + else if (mpq_set_str(mp, s, base) != 0) + { + mpq_clear (mp); + throw std::invalid_argument ("mpq_set_str"); + } + } + explicit __gmp_expr(const std::string &s, int base = 0) + { + mpq_init(mp); + if (mpq_set_str (mp, s.c_str(), base) != 0) + { + mpq_clear (mp); + throw std::invalid_argument ("mpq_set_str"); + } + } + explicit __gmp_expr(mpq_srcptr q) + { + mpz_init_set(mpq_numref(mp), mpq_numref(q)); + mpz_init_set(mpq_denref(mp), mpq_denref(q)); + } + + __gmp_expr(const mpz_class &num, const mpz_class &den) + { + mpz_init_set(mpq_numref(mp), num.get_mpz_t()); + mpz_init_set(mpq_denref(mp), den.get_mpz_t()); + } + + ~__gmp_expr() { mpq_clear(mp); } + + void swap(__gmp_expr& q) __GMPXX_NOEXCEPT { std::swap(*mp, *q.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &q) + { mpq_set(mp, q.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&q) __GMPXX_NOEXCEPT + { swap(q); return *this; } + __gmp_expr & operator=(mpz_class &&z)__GMPXX_NOEXCEPT + { get_num() = std::move(z); get_den() = 1u; return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + + __gmp_expr & operator=(signed char c) + { mpq_set_si(mp, c, 1); return *this; } + __gmp_expr & operator=(unsigned char c) + { mpq_set_ui(mp, c, 1); return *this; } + + __gmp_expr & operator=(signed int i) { mpq_set_si(mp, i, 1); return *this; } + __gmp_expr & operator=(unsigned int i) + { mpq_set_ui(mp, i, 1); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpq_set_si(mp, s, 1); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpq_set_ui(mp, s, 1); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpq_set_si(mp, l, 1); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpq_set_ui(mp, l, 1); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int l) + { mpq_set_si(mp, l, 1); return *this; } + __gmp_expr & operator=(unsigned long long int l) + { mpq_set_ui(mp, l, 1); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpq_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpq_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpq_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpq_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpq_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpq_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpq_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpq_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpq_set_str(mp, s.c_str(), base); } + std::string get_str(int base = 10) const + { + __gmp_alloc_cstring temp(mpq_get_str(0, base, mp)); + return std::string(temp.str); + } + + // conversion functions + + // casting a reference to an mpz_t to mpz_class & is a dirty hack, + // but works because the internal representation of mpz_class is + // exactly an mpz_t + const mpz_class & get_num() const + { return reinterpret_cast(*mpq_numref(mp)); } + mpz_class & get_num() + { return reinterpret_cast(*mpq_numref(mp)); } + const mpz_class & get_den() const + { return reinterpret_cast(*mpq_denref(mp)); } + mpz_class & get_den() + { return reinterpret_cast(*mpq_denref(mp)); } + + mpq_srcptr __get_mp() const { return mp; } + mpq_ptr __get_mp() { return mp; } + mpq_srcptr get_mpq_t() const { return mp; } + mpq_ptr get_mpq_t() { return mp; } + + mpz_srcptr get_num_mpz_t() const { return mpq_numref(mp); } + mpz_ptr get_num_mpz_t() { return mpq_numref(mp); } + mpz_srcptr get_den_mpz_t() const { return mpq_denref(mp); } + mpz_ptr get_den_mpz_t() { return mpq_denref(mp); } + + double get_d() const { return mpq_get_d(mp); } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mpq_numref(mp)->_mp_size != 0; } +#endif + + // compound assignments + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpq_class; + + +/**************** mpf_class -- wrapper for mpf_t ****************/ + +template <> +class __gmp_expr +{ +private: + typedef mpf_t value_type; + value_type mp; +public: + mp_bitcnt_t get_prec() const { return mpf_get_prec(mp); } + + void set_prec(mp_bitcnt_t prec) { mpf_set_prec(mp, prec); } + void set_prec_raw(mp_bitcnt_t prec) { mpf_set_prec_raw(mp, prec); } + + // constructors and destructor + __gmp_expr() { mpf_init(mp); } + + __gmp_expr(const __gmp_expr &f) + { mpf_init2(mp, f.get_prec()); mpf_set(mp, f.mp); } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr(__gmp_expr &&f) + { *mp = *f.mp; mpf_init2(f.mp, get_prec()); } +#endif + __gmp_expr(const __gmp_expr &f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set(mp, f.mp); } + template + __gmp_expr(const __gmp_expr &expr) + { mpf_init2(mp, expr.get_prec()); __gmp_set_expr(mp, expr); } + template + __gmp_expr(const __gmp_expr &expr, mp_bitcnt_t prec) + { mpf_init2(mp, prec); __gmp_set_expr(mp, expr); } + + __gmp_expr(signed char c) { mpf_init_set_si(mp, c); } + __gmp_expr(signed char c, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, c); } + __gmp_expr(unsigned char c) { mpf_init_set_ui(mp, c); } + __gmp_expr(unsigned char c, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, c); } + + __gmp_expr(signed int i) { mpf_init_set_si(mp, i); } + __gmp_expr(signed int i, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, i); } + __gmp_expr(unsigned int i) { mpf_init_set_ui(mp, i); } + __gmp_expr(unsigned int i, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, i); } + + __gmp_expr(signed short int s) { mpf_init_set_si(mp, s); } + __gmp_expr(signed short int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, s); } + __gmp_expr(unsigned short int s) { mpf_init_set_ui(mp, s); } + __gmp_expr(unsigned short int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, s); } + + __gmp_expr(signed long int l) { mpf_init_set_si(mp, l); } + __gmp_expr(signed long int l, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, l); } + __gmp_expr(unsigned long int l) { mpf_init_set_ui(mp, l); } + __gmp_expr(unsigned long int l, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, l); } +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr(signed long long int s) { mpf_init_set_si(mp, s); } + __gmp_expr(signed long long int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_si(mp, s); } + __gmp_expr(unsigned long long int s) { mpf_init_set_ui(mp, s); } + __gmp_expr(unsigned long long int s, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_ui(mp, s); } +#endif + + __gmp_expr(float f) { mpf_init_set_d(mp, f); } + __gmp_expr(float f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_d(mp, f); } + __gmp_expr(double d) { mpf_init_set_d(mp, d); } + __gmp_expr(double d, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set_d(mp, d); } + // __gmp_expr(long double ld) { mpf_init_set_d(mp, ld); } + // __gmp_expr(long double ld, mp_bitcnt_t prec) + // { mpf_init2(mp, prec); mpf_set_d(mp, ld); } + + explicit __gmp_expr(const char *s) + { + if (mpf_init_set_str (mp, s, 0) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + __gmp_expr(const char *s, mp_bitcnt_t prec, int base = 0) + { + mpf_init2(mp, prec); + if (mpf_set_str(mp, s, base) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + explicit __gmp_expr(const std::string &s) + { + if (mpf_init_set_str(mp, s.c_str(), 0) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + __gmp_expr(const std::string &s, mp_bitcnt_t prec, int base = 0) + { + mpf_init2(mp, prec); + if (mpf_set_str(mp, s.c_str(), base) != 0) + { + mpf_clear (mp); + throw std::invalid_argument ("mpf_set_str"); + } + } + + explicit __gmp_expr(mpf_srcptr f) + { mpf_init2(mp, mpf_get_prec(f)); mpf_set(mp, f); } + __gmp_expr(mpf_srcptr f, mp_bitcnt_t prec) + { mpf_init2(mp, prec); mpf_set(mp, f); } + + ~__gmp_expr() { mpf_clear(mp); } + + void swap(__gmp_expr& f) __GMPXX_NOEXCEPT { std::swap(*mp, *f.mp); } + + // assignment operators + __gmp_expr & operator=(const __gmp_expr &f) + { mpf_set(mp, f.mp); return *this; } +#if __GMPXX_USE_CXX11 || defined( MSC_CXX_11 ) + __gmp_expr & operator=(__gmp_expr &&f) __GMPXX_NOEXCEPT + { swap(f); return *this; } +#endif + template + __gmp_expr & operator=(const __gmp_expr &expr) + { __gmp_set_expr(mp, expr); return *this; } + + __gmp_expr & operator=(signed char c) { mpf_set_si(mp, c); return *this; } + __gmp_expr & operator=(unsigned char c) { mpf_set_ui(mp, c); return *this; } + + __gmp_expr & operator=(signed int i) { mpf_set_si(mp, i); return *this; } + __gmp_expr & operator=(unsigned int i) { mpf_set_ui(mp, i); return *this; } + + __gmp_expr & operator=(signed short int s) + { mpf_set_si(mp, s); return *this; } + __gmp_expr & operator=(unsigned short int s) + { mpf_set_ui(mp, s); return *this; } + + __gmp_expr & operator=(signed long int l) + { mpf_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long int l) + { mpf_set_ui(mp, l); return *this; } + +#ifdef MPIRXX_HAVE_LLONG + __gmp_expr & operator=(signed long long int l) + { mpf_set_si(mp, l); return *this; } + __gmp_expr & operator=(unsigned long long int l) + { mpf_set_ui(mp, l); return *this; } +#endif + + __gmp_expr & operator=(float f) { mpf_set_d(mp, f); return *this; } + __gmp_expr & operator=(double d) { mpf_set_d(mp, d); return *this; } + // __gmp_expr & operator=(long double ld) + // { mpf_set_ld(mp, ld); return *this; } + + __gmp_expr & operator=(const char *s) + { + if (mpf_set_str (mp, s, 0) != 0) + throw std::invalid_argument ("mpf_set_str"); + return *this; + } + __gmp_expr & operator=(const std::string &s) + { + if (mpf_set_str(mp, s.c_str(), 0) != 0) + throw std::invalid_argument ("mpf_set_str"); + return *this; + } + + // string input/output functions + int set_str(const char *s, int base) + { return mpf_set_str(mp, s, base); } + int set_str(const std::string &s, int base) + { return mpf_set_str(mp, s.c_str(), base); } + std::string get_str(mp_exp_t &expo, int base = 10, size_t size = 0) const + { + __gmp_alloc_cstring temp(mpf_get_str(0, &expo, base, size, mp)); + return std::string(temp.str); + } + + // conversion functions + mpf_srcptr __get_mp() const { return mp; } + mpf_ptr __get_mp() { return mp; } + mpf_srcptr get_mpf_t() const { return mp; } + mpf_ptr get_mpf_t() { return mp; } + + mpir_si get_si() const { return mpf_get_si(mp); } + mpir_ui get_ui() const { return mpf_get_ui(mp); } + double get_d() const { return mpf_get_d(mp); } + + // bool fits_schar_p() const { return mpf_fits_schar_p(mp)!= 0; } + // bool fits_uchar_p() const { return mpf_fits_uchar_p(mp)!= 0; } + bool fits_sint_p() const { return mpf_fits_sint_p(mp) != 0; } + bool fits_uint_p() const { return mpf_fits_uint_p(mp) != 0; } + bool fits_si_p() const { return mpf_fits_si_p(mp) != 0; } + bool fits_ui_p() const { return mpf_fits_ui_p(mp) != 0; } + bool fits_sshort_p() const { return mpf_fits_sshort_p(mp) != 0; } + bool fits_ushort_p() const { return mpf_fits_ushort_p(mp) != 0; } + bool fits_slong_p() const { return mpf_fits_slong_p(mp) != 0; } + bool fits_ulong_p() const { return mpf_fits_ulong_p(mp) != 0; } + // bool fits_float_p() const { return mpf_fits_float_p(mp)!= 0; } + // bool fits_double_p() const { return mpf_fits_double_p(mp)!= 0; } + // bool fits_ldouble_p() const { return mpf_fits_ldouble_p(mp)!= 0; } + +#if __GMPXX_USE_CXX11 + explicit operator bool() const { return mp->_mp_size != 0; } +#endif + + // compound assignments + __GMP_DECLARE_COMPOUND_OPERATOR(operator+=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator-=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator*=) + __GMP_DECLARE_COMPOUND_OPERATOR(operator/=) + + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator<<=) + __GMP_DECLARE_COMPOUND_OPERATOR_UI(operator>>=) + + __GMP_DECLARE_INCREMENT_OPERATOR(operator++) + __GMP_DECLARE_INCREMENT_OPERATOR(operator--) +}; + +typedef __gmp_expr mpf_class; + + + +/**************** User-defined literals ****************/ + +#if __GMPXX_USE_CXX11 +inline mpz_class operator"" _mpz(const char* s) +{ + return mpz_class(s); +} + +inline mpq_class operator"" _mpq(const char* s) +{ + mpq_class q; + q.get_num() = s; + return q; +} + +inline mpf_class operator"" _mpf(const char* s) +{ + return mpf_class(s); +} +#endif + +/**************** I/O operators ****************/ + +// these should (and will) be provided separately + +template +inline std::ostream & operator<< +(std::ostream &o, const __gmp_expr &expr) +{ + __gmp_expr const& temp(expr); + return o << temp.__get_mp(); +} + +template +inline std::istream & operator>>(std::istream &i, __gmp_expr &expr) +{ + return i >> expr.__get_mp(); +} + +/* +// you might want to uncomment this +inline std::istream & operator>>(std::istream &i, mpq_class &q) +{ + i >> q.get_mpq_t(); + q.canonicalize(); + return i; +} +*/ + + +/**************** Functions for type conversion ****************/ + +inline void __gmp_set_expr(mpz_ptr z, const mpz_class &w) +{ + mpz_set(z, w.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + expr.eval(z); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + mpq_class const& temp(expr); + mpz_set_q(z, temp.get_mpq_t()); +} + +template +inline void __gmp_set_expr(mpz_ptr z, const __gmp_expr &expr) +{ + mpf_class const& temp(expr); + mpz_set_f(z, temp.get_mpf_t()); +} + +inline void __gmp_set_expr(mpq_ptr q, const mpz_class &z) +{ + mpq_set_z(q, z.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + __gmp_set_expr(mpq_numref(q), expr); + mpz_set_ui(mpq_denref(q), 1); +} + +inline void __gmp_set_expr(mpq_ptr q, const mpq_class &r) +{ + mpq_set(q, r.get_mpq_t()); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + expr.eval(q); +} + +template +inline void __gmp_set_expr(mpq_ptr q, const __gmp_expr &expr) +{ + mpf_class const& temp(expr); + mpq_set_f(q, temp.get_mpf_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + mpz_class const& temp(expr); + mpf_set_z(f, temp.get_mpz_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + mpq_class const& temp(expr); + mpf_set_q(f, temp.get_mpq_t()); +} + +inline void __gmp_set_expr(mpf_ptr f, const mpf_class &g) +{ + mpf_set(f, g.get_mpf_t()); +} + +template +inline void __gmp_set_expr(mpf_ptr f, const __gmp_expr &expr) +{ + expr.eval(f); +} + + +/* Temporary objects */ + +template +class __gmp_temp +{ + __gmp_expr val; + public: + template + __gmp_temp(U const& u, V) : val (u) {} + typename __gmp_resolve_expr::srcptr_type + __get_mp() const { return val.__get_mp(); } +}; + +template <> +class __gmp_temp +{ + mpf_class val; + public: + template + __gmp_temp(U const& u, mpf_ptr res) : val (u, mpf_get_prec(res)) {} + mpf_srcptr __get_mp() const { return val.__get_mp(); } +}; + +/**************** Specializations of __gmp_expr ****************/ +/* The eval() method of __gmp_expr evaluates the corresponding + expression and assigns the result to its argument, which is either an + mpz_t, mpq_t, or mpf_t as specified by the T argument. + Compound expressions are evaluated recursively (temporaries are created + to hold intermediate values), while for simple expressions the eval() + method of the appropriate function object (available as the Op argument + of either __gmp_unary_expr or __gmp_binary_expr) is + called. */ + + +/**************** Unary expressions ****************/ +/* cases: + - simple: argument is mp*_class, that is, __gmp_expr + - compound: argument is __gmp_expr (with U not equal to T) */ + + +// simple expressions + +template +class __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val_type; + + __gmp_unary_expr expr; +public: + explicit __gmp_expr(const val_type &val) : expr(val) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val.__get_mp()); } + const val_type & get_val() const { return expr.val; } + mp_bitcnt_t get_prec() const { return expr.val.get_prec(); } +}; + + +// compound expressions + +template +class __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val_type; + + __gmp_unary_expr expr; +public: + explicit __gmp_expr(const val_type &val) : expr(val) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { expr.val.eval(p); Op::eval(p, p); } + const val_type & get_val() const { return expr.val; } + mp_bitcnt_t get_prec() const { return expr.val.get_prec(); } +}; + + +/**************** Binary expressions ****************/ +/* simple: + - arguments are both mp*_class + - one argument is mp*_class, one is a built-in type + compound: + - one is mp*_class, one is __gmp_expr + - one is __gmp_expr, one is built-in + - both arguments are __gmp_expr<...> */ + + +// simple expressions + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1.__get_mp(), expr.val2.__get_mp()); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +// simple expressions, T is a built-in numerical type + +template +class __gmp_expr, U, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef U val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1.__get_mp(), expr.val2); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val1.get_prec(); } +}; + +template +class __gmp_expr, Op> > +{ +private: + typedef U val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { Op::eval(p, expr.val1, expr.val2.__get_mp()); } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val2.get_prec(); } +}; + + +// compound expressions, one argument is a subexpression + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val1.__get_mp()) + { + __gmp_set_expr(p, expr.val2); + Op::eval(p, expr.val1.__get_mp(), p); + } + else + { + __gmp_temp temp(expr.val2, p); + Op::eval(p, expr.val1.__get_mp(), temp.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val2.__get_mp()) + { + __gmp_set_expr(p, expr.val1); + Op::eval(p, p, expr.val2.__get_mp()); + } + else + { + __gmp_temp temp(expr.val1, p); + Op::eval(p, temp.__get_mp(), expr.val2.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val1.__get_mp()) + { + __gmp_set_expr(p, expr.val2); + Op::eval(p, expr.val1.__get_mp(), p); + } + else + { + __gmp_temp temp(expr.val2, p); + Op::eval(p, expr.val1.__get_mp(), temp.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + if(p != expr.val2.__get_mp()) + { + __gmp_set_expr(p, expr.val1); + Op::eval(p, p, expr.val2.__get_mp()); + } + else + { + __gmp_temp temp(expr.val1, p); + Op::eval(p, temp.__get_mp(), expr.val2.__get_mp()); + } + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +// one argument is a subexpression, one is a built-in + +template +class __gmp_expr, V, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef V val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + expr.val1.eval(p); + Op::eval(p, p, expr.val2); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val1.get_prec(); } +}; + +template +class __gmp_expr, Op> > +{ +private: + typedef U val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + expr.val2.eval(p); + Op::eval(p, expr.val1, p); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const { return expr.val2.get_prec(); } +}; + + +// both arguments are subexpressions + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp2(expr.val2, p); + expr.val1.eval(p); + Op::eval(p, p, temp2.__get_mp()); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp1(expr.val1, p); + expr.val2.eval(p); + Op::eval(p, temp1.__get_mp(), p); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + +template +class __gmp_expr +, __gmp_expr, Op> > +{ +private: + typedef __gmp_expr val1_type; + typedef __gmp_expr val2_type; + + __gmp_binary_expr expr; +public: + __gmp_expr(const val1_type &val1, const val2_type &val2) + : expr(val1, val2) { } + void eval(typename __gmp_resolve_expr::ptr_type p) const + { + __gmp_temp temp2(expr.val2, p); + expr.val1.eval(p); + Op::eval(p, p, temp2.__get_mp()); + } + const val1_type & get_val1() const { return expr.val1; } + const val2_type & get_val2() const { return expr.val2; } + mp_bitcnt_t get_prec() const + { + mp_bitcnt_t prec1 = expr.val1.get_prec(), + prec2 = expr.val2.get_prec(); + return (prec1 > prec2) ? prec1 : prec2; + } +}; + + +/**************** Special cases ****************/ + +/* Some operations (i.e., add and subtract) with mixed mpz/mpq arguments + can be done directly without first converting the mpz to mpq. + Appropriate specializations of __gmp_expr are required. */ + + +#define __GMPZQ_DEFINE_EXPR(eval_fun) \ + \ +template <> \ +class __gmp_expr > \ +{ \ +private: \ + typedef mpz_class val1_type; \ + typedef mpq_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { eval_fun::eval(q, expr.val1.get_mpz_t(), expr.val2.get_mpq_t()); } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template <> \ +class __gmp_expr > \ +{ \ +private: \ + typedef mpq_class val1_type; \ + typedef mpz_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { eval_fun::eval(q, expr.val1.get_mpq_t(), expr.val2.get_mpz_t()); } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, eval_fun> > \ +{ \ +private: \ + typedef mpz_class val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpq_class temp(expr.val2); \ + eval_fun::eval(q, expr.val1.get_mpz_t(), temp.get_mpq_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, eval_fun> > \ +{ \ +private: \ + typedef mpq_class val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp(expr.val2); \ + eval_fun::eval(q, expr.val1.get_mpq_t(), temp.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, mpq_class, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef mpq_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp(expr.val1); \ + eval_fun::eval(q, temp.get_mpz_t(), expr.val2.get_mpq_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr \ +, mpz_class, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef mpz_class val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpq_class temp(expr.val1); \ + eval_fun::eval(q, temp.get_mpq_t(), expr.val2.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr, __gmp_expr, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp1(expr.val1); \ + expr.val2.eval(q); \ + eval_fun::eval(q, temp1.get_mpz_t(), q); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; \ + \ +template \ +class __gmp_expr, __gmp_expr, eval_fun> > \ +{ \ +private: \ + typedef __gmp_expr val1_type; \ + typedef __gmp_expr val2_type; \ + \ + __gmp_binary_expr expr; \ +public: \ + __gmp_expr(const val1_type &val1, const val2_type &val2) \ + : expr(val1, val2) { } \ + void eval(mpq_ptr q) const \ + { \ + mpz_class temp2(expr.val2); \ + expr.val1.eval(q); \ + eval_fun::eval(q, q, temp2.get_mpz_t()); \ + } \ + const val1_type & get_val1() const { return expr.val1; } \ + const val2_type & get_val2() const { return expr.val2; } \ + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } \ +}; + + +__GMPZQ_DEFINE_EXPR(__gmp_binary_plus) +__GMPZQ_DEFINE_EXPR(__gmp_binary_minus) + + + +/**************** Macros for defining functions ****************/ +/* Results of operators and functions are instances of __gmp_expr. + T determines the numerical type of the expression: it can be either + mpz_t, mpq_t, or mpf_t. When the arguments of a binary + expression have different numerical types, __gmp_resolve_expr is used + to determine the "larger" type. + U is either __gmp_unary_expr or __gmp_binary_expr, + where V and W are the arguments' types -- they can in turn be + expressions, thus allowing to build compound expressions to any + degree of complexity. + Op is a function object that must have an eval() method accepting + appropriate arguments. + Actual evaluation of a __gmp_expr object is done when it gets + assigned to an mp*_class ("lazy" evaluation): this is done by calling + its eval() method. */ + + +// non-member unary operators and functions + +#define __GMP_DEFINE_UNARY_FUNCTION(fun, eval_fun) \ + \ +template \ +inline __gmp_expr, eval_fun> > \ +fun(const __gmp_expr &expr) \ +{ \ + return __gmp_expr, eval_fun> >(expr); \ +} + +#define __GMP_DEFINE_UNARY_TYPE_FUNCTION(type, fun, eval_fun) \ + \ +template \ +inline type fun(const __gmp_expr &expr) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(temp.__get_mp()); \ +} + + +// non-member binary operators and functions + +#define __GMPP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ + \ +template \ +inline __gmp_expr::value_type, \ +__gmp_binary_expr<__gmp_expr, __gmp_expr, eval_fun> > \ +fun(const __gmp_expr &expr1, const __gmp_expr &expr2) \ +{ \ + return __gmp_expr::value_type, \ + __gmp_binary_expr<__gmp_expr, __gmp_expr, eval_fun> > \ + (expr1, expr2); \ +} + +#define __GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, bigtype) \ + \ +template \ +inline __gmp_expr \ +, bigtype, eval_fun> > \ +fun(const __gmp_expr &expr, type t) \ +{ \ + return __gmp_expr \ + , bigtype, eval_fun> >(expr, t); \ +} \ + \ +template \ +inline __gmp_expr \ +, eval_fun> > \ +fun(type t, const __gmp_expr &expr) \ +{ \ + return __gmp_expr \ + , eval_fun> >(t, expr); \ +} + +#define __GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, mpir_si) + +#define __GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, mpir_ui) + +#define __GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, double) + +#define __GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, type) \ +__GMPNN_DEFINE_BINARY_FUNCTION(fun, eval_fun, type, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, long double) +#else +#define __GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_FUNCTION(fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_FUNCTION(fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_FUNCTION(fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_FUNCTION(fun, eval_fun, long double) +#endif + +#define __GMP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPP_DEFINE_BINARY_FUNCTION(fun, eval_fun) \ +__GMPN_DEFINE_BINARY_FUNCTION(fun, eval_fun) + + +#define __GMP_DEFINE_BINARY_FUNCTION_UI(fun, eval_fun) \ + \ +template \ +inline __gmp_expr \ +, mp_bitcnt_t, eval_fun> > \ +fun(const __gmp_expr &expr, mp_bitcnt_t l) \ +{ \ + return __gmp_expr, mpir_ui, eval_fun> >(expr, l); \ +} + + +#define __GMPP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ + \ +template \ +inline type fun(const __gmp_expr &expr1, \ + const __gmp_expr &expr2) \ +{ \ + typedef typename __gmp_resolve_expr::value_type eval_type; \ + __gmp_expr const& temp1(expr1); \ + __gmp_expr const& temp2(expr2); \ + return eval_fun::eval(temp1.__get_mp(), temp2.__get_mp()); \ +} + +#define __GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, bigtype) \ + \ +template \ +inline type fun(const __gmp_expr &expr, type2 t) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(temp.__get_mp(), static_cast(t)); \ +} \ + \ +template \ +inline type fun(type2 t, const __gmp_expr &expr) \ +{ \ + __gmp_expr const& temp(expr); \ + return eval_fun::eval(static_cast(t), temp.__get_mp()); \ +} + +#define __GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, mpir_si) + +#define __GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, \ + type2, mpir_ui) + +#define __GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2, double) + +#define __GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, type2, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, long double) +#else +#define __GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, float) \ +__GMPND_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, double) \ +__GMPNLD_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun, long double) +#endif + +#define __GMP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPP_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) \ +__GMPN_DEFINE_BINARY_TYPE_FUNCTION(type, fun, eval_fun) + + +// member operators + +#define __GMPP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ + \ +template \ +inline type##_class & type##_class::fun(const __gmp_expr &expr) \ +{ \ + __gmp_set_expr(mp, __gmp_expr, eval_fun> >(*this, expr)); \ + return *this; \ +} + +#define __GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, bigtype) \ + \ +inline type##_class & type##_class::fun(type2 t) \ +{ \ + __gmp_set_expr(mp, __gmp_expr >(*this, t)); \ + return *this; \ +} + +#define __GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, mpir_si) + +#define __GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, \ + type2, mpir_ui) + +#define __GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2, double) + +#define __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2) \ +__GMPNN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, type2, long double) + +#ifdef MPIRXX_HAVE_LLONG +#define __GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long long int) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, float) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, double) \ +/* __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, long double) */ +#else +#define __GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed char) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned char) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed short int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned short int) \ +__GMPNS_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, signed long int) \ +__GMPNU_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, unsigned long int) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, float) \ +__GMPND_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, double) \ +/* __GMPNLD_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun, long double) */ +#endif + +#define __GMP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPP_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) \ +__GMPN_DEFINE_COMPOUND_OPERATOR(type, fun, eval_fun) + +#define __GMPZ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_COMPOUND_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR(mpf, fun, eval_fun) + + + +#define __GMP_DEFINE_COMPOUND_OPERATOR_UI(type, fun, eval_fun) \ + \ +inline type##_class & type##_class::fun(mpir_ui l) \ +{ \ + __gmp_set_expr(mp, __gmp_expr >(*this, l)); \ + return *this; \ +} + +#define __GMPZ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_COMPOUND_OPERATOR_UI(fun, eval_fun) \ +__GMP_DEFINE_COMPOUND_OPERATOR_UI(mpf, fun, eval_fun) + + + +#define __GMP_DEFINE_INCREMENT_OPERATOR(type, fun, eval_fun) \ + \ +inline type##_class & type##_class::fun() \ +{ \ + eval_fun::eval(mp); \ + return *this; \ +} \ + \ +inline type##_class type##_class::fun(int) \ +{ \ + type##_class temp(*this); \ + eval_fun::eval(mp); \ + return temp; \ +} + +#define __GMPZ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpz, fun, eval_fun) + +#define __GMPQ_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpq, fun, eval_fun) + +#define __GMPF_DEFINE_INCREMENT_OPERATOR(fun, eval_fun) \ +__GMP_DEFINE_INCREMENT_OPERATOR(mpf, fun, eval_fun) + + + +/**************** Arithmetic operators and functions ****************/ + +// non-member operators and functions + +__GMP_DEFINE_UNARY_FUNCTION(operator+, __gmp_unary_plus) +__GMP_DEFINE_UNARY_FUNCTION(operator-, __gmp_unary_minus) +__GMP_DEFINE_UNARY_FUNCTION(operator~, __gmp_unary_com) + +__GMP_DEFINE_BINARY_FUNCTION(operator+, __gmp_binary_plus) +__GMP_DEFINE_BINARY_FUNCTION(operator-, __gmp_binary_minus) +__GMP_DEFINE_BINARY_FUNCTION(operator*, __gmp_binary_multiplies) +__GMP_DEFINE_BINARY_FUNCTION(operator/, __gmp_binary_divides) +__GMP_DEFINE_BINARY_FUNCTION(operator%, __gmp_binary_modulus) +__GMP_DEFINE_BINARY_FUNCTION(operator&, __gmp_binary_and) +__GMP_DEFINE_BINARY_FUNCTION(operator|, __gmp_binary_ior) +__GMP_DEFINE_BINARY_FUNCTION(operator^, __gmp_binary_xor) + +__GMP_DEFINE_BINARY_FUNCTION_UI(operator<<, __gmp_binary_lshift) +__GMP_DEFINE_BINARY_FUNCTION_UI(operator>>, __gmp_binary_rshift) + +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator==, __gmp_binary_equal) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator!=, ! __gmp_binary_equal) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<, __gmp_binary_less) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator<=, ! __gmp_binary_greater) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>, __gmp_binary_greater) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(bool, operator>=, ! __gmp_binary_less) + +__GMP_DEFINE_UNARY_FUNCTION(abs, __gmp_abs_function) +__GMP_DEFINE_UNARY_FUNCTION(trunc, __gmp_trunc_function) +__GMP_DEFINE_UNARY_FUNCTION(floor, __gmp_floor_function) +__GMP_DEFINE_UNARY_FUNCTION(ceil, __gmp_ceil_function) +__GMP_DEFINE_UNARY_FUNCTION(sqrt, __gmp_sqrt_function) +__GMP_DEFINE_BINARY_FUNCTION(hypot, __gmp_hypot_function) + +__GMP_DEFINE_UNARY_TYPE_FUNCTION(int, sgn, __gmp_sgn_function) +__GMP_DEFINE_BINARY_TYPE_FUNCTION(int, cmp, __gmp_cmp_function) + +template +void swap(__gmp_expr& x, __gmp_expr& y) __GMPXX_NOEXCEPT +{ x.swap(y); } + +// member operators for mpz_class + +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator%=, __gmp_binary_modulus) + +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator&=, __gmp_binary_and) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator|=, __gmp_binary_ior) +__GMPZ_DEFINE_COMPOUND_OPERATOR(operator^=, __gmp_binary_xor) + +__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPZ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPZ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPZ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + +// member operators for mpq_class + +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPQ_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) + +__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPQ_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPQ_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPQ_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + +// member operators for mpf_class + +__GMPF_DEFINE_COMPOUND_OPERATOR(operator+=, __gmp_binary_plus) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator-=, __gmp_binary_minus) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator*=, __gmp_binary_multiplies) +__GMPF_DEFINE_COMPOUND_OPERATOR(operator/=, __gmp_binary_divides) + +__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator<<=, __gmp_binary_lshift) +__GMPF_DEFINE_COMPOUND_OPERATOR_UI(operator>>=, __gmp_binary_rshift) + +__GMPF_DEFINE_INCREMENT_OPERATOR(operator++, __gmp_unary_increment) +__GMPF_DEFINE_INCREMENT_OPERATOR(operator--, __gmp_unary_decrement) + + + +/**************** Class wrapper for gmp_randstate_t ****************/ + +class __gmp_urandomb_value { }; +class __gmp_urandomm_value { }; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mp_bitcnt_t bits; +public: + __gmp_expr(gmp_randstate_t s, mp_bitcnt_t l) : state(s), bits(l) { } + void eval(mpz_ptr z) const { __gmp_rand_function::eval(z, state, bits); } + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } +}; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mpz_class range; +public: + __gmp_expr(gmp_randstate_t s, const mpz_class &z) : state(s), range(z) { } + void eval(mpz_ptr z) const + { __gmp_rand_function::eval(z, state, range.get_mpz_t()); } + mp_bitcnt_t get_prec() const { return mpf_get_default_prec(); } +}; + +template <> +class __gmp_expr +{ +private: + __gmp_randstate_struct *state; + mp_bitcnt_t bits; +public: + __gmp_expr(gmp_randstate_t s, mp_bitcnt_t l) : state(s), bits(l) { } + void eval(mpf_ptr f) const + { + __gmp_rand_function::eval(f, state, + (bits>0) ? bits : mpf_get_prec(f)); + } + mp_bitcnt_t get_prec() const + { + if (bits == 0) + return mpf_get_default_prec(); + else + return bits; + } +}; + +extern "C" { + typedef void __gmp_randinit_default_t (gmp_randstate_t); + typedef void __gmp_randinit_lc_2exp_t (gmp_randstate_t, mpz_srcptr, mpir_ui, mp_bitcnt_t); + typedef int __gmp_randinit_lc_2exp_size_t (gmp_randstate_t, mp_bitcnt_t); +} + +class gmp_randclass +{ +private: + gmp_randstate_t state; + + // copy construction and assignment not allowed + gmp_randclass(const gmp_randclass &); + void operator=(const gmp_randclass &); +public: + // constructors and destructor + gmp_randclass(gmp_randalg_t alg, mp_bitcnt_t size) + { + switch (alg) + { + case GMP_RAND_ALG_LC: // no other cases for now + default: + gmp_randinit(state, alg, size); + break; + } + } + + // gmp_randinit_default + gmp_randclass(__gmp_randinit_default_t* f) { f(state); } + + // gmp_randinit_lc_2exp + gmp_randclass(__gmp_randinit_lc_2exp_t* f, + mpz_class z, mpir_ui l1, mp_bitcnt_t l2) + { f(state, z.get_mpz_t(), l1, l2); } + + // gmp_randinit_lc_2exp_size + gmp_randclass(__gmp_randinit_lc_2exp_size_t* f, + mp_bitcnt_t size) + { + if (f (state, size) == 0) + throw std::length_error ("gmp_randinit_lc_2exp_size"); + } + + ~gmp_randclass() { gmp_randclear(state); } + + // initialize + void seed(); // choose a random seed some way (?) + void seed(mpir_ui s) { gmp_randseed_ui(state, s); } + void seed(const mpz_class &z) { gmp_randseed(state, z.get_mpz_t()); } + + // get random number + __gmp_expr get_z_bits(mp_bitcnt_t l) + { return __gmp_expr(state, l); } + __gmp_expr get_z_bits(const mpz_class &z) + { return get_z_bits(z.get_ui()); } + // FIXME: z.get_bitcnt_t() ? + + __gmp_expr get_z_range(const mpz_class &z) + { return __gmp_expr(state, z); } + + __gmp_expr get_f(mp_bitcnt_t prec = 0) + { return __gmp_expr(state, prec); } +}; + + +/**************** Specialize std::numeric_limits ****************/ + +namespace std { + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpz_class min() { return mpz_class(); } + static mpz_class max() { return mpz_class(); } + static mpz_class lowest() { return mpz_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const int radix = 2; + static mpz_class epsilon() { return mpz_class(); } + static mpz_class round_error() { return mpz_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpz_class infinity() { return mpz_class(); } + static mpz_class quiet_NaN() { return mpz_class(); } + static mpz_class signaling_NaN() { return mpz_class(); } + static mpz_class denorm_min() { return mpz_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; + }; + + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpq_class min() { return mpq_class(); } + static mpq_class max() { return mpq_class(); } + static mpq_class lowest() { return mpq_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = true; + static const int radix = 2; + static mpq_class epsilon() { return mpq_class(); } + static mpq_class round_error() { return mpq_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpq_class infinity() { return mpq_class(); } + static mpq_class quiet_NaN() { return mpq_class(); } + static mpq_class signaling_NaN() { return mpq_class(); } + static mpq_class denorm_min() { return mpq_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; + }; + + template <> class numeric_limits + { + public: + static const bool is_specialized = true; + static mpf_class min() { return mpf_class(); } + static mpf_class max() { return mpf_class(); } + static mpf_class lowest() { return mpf_class(); } + static const int digits = 0; + static const int digits10 = 0; + static const int max_digits10 = 0; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const int radix = 2; + static mpf_class epsilon() { return mpf_class(); } + static mpf_class round_error() { return mpf_class(); } + static const int min_exponent = 0; + static const int min_exponent10 = 0; + static const int max_exponent = 0; + static const int max_exponent10 = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const float_denorm_style has_denorm = denorm_absent; + static const bool has_denorm_loss = false; + static mpf_class infinity() { return mpf_class(); } + static mpf_class quiet_NaN() { return mpf_class(); } + static mpf_class signaling_NaN() { return mpf_class(); } + static mpf_class denorm_min() { return mpf_class(); } + static const bool is_iec559 = false; + static const bool is_bounded = false; + static const bool is_modulo = false; + static const bool traps = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + }; +} + + +/**************** #undef all private macros ****************/ + +#undef __GMPP_DECLARE_COMPOUND_OPERATOR +#undef __GMPN_DECLARE_COMPOUND_OPERATOR +#undef __GMP_DECLARE_COMPOUND_OPERATOR +#undef __GMP_DECLARE_COMPOUND_OPERATOR_UI +#undef __GMP_DECLARE_INCREMENT_OPERATOR + +#undef __GMPZQ_DEFINE_EXPR + +#undef __GMP_DEFINE_UNARY_FUNCTION +#undef __GMP_DEFINE_UNARY_TYPE_FUNCTION + +#undef __GMPP_DEFINE_BINARY_FUNCTION +#undef __GMPNN_DEFINE_BINARY_FUNCTION +#undef __GMPNS_DEFINE_BINARY_FUNCTION +#undef __GMPNU_DEFINE_BINARY_FUNCTION +#undef __GMPND_DEFINE_BINARY_FUNCTION +#undef __GMPNLD_DEFINE_BINARY_FUNCTION +#undef __GMPN_DEFINE_BINARY_FUNCTION +#undef __GMP_DEFINE_BINARY_FUNCTION + +#undef __GMP_DEFINE_BINARY_FUNCTION_UI + +#undef __GMPP_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNN_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNS_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNU_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPND_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPNLD_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMPN_DEFINE_BINARY_TYPE_FUNCTION +#undef __GMP_DEFINE_BINARY_TYPE_FUNCTION + +#undef __GMPZ_DEFINE_COMPOUND_OPERATOR + +#undef __GMPP_DEFINE_COMPOUND_OPERATOR +#undef __GMPNN_DEFINE_COMPOUND_OPERATOR +#undef __GMPNS_DEFINE_COMPOUND_OPERATOR +#undef __GMPNU_DEFINE_COMPOUND_OPERATOR +#undef __GMPND_DEFINE_COMPOUND_OPERATOR +#undef __GMPNLD_DEFINE_COMPOUND_OPERATOR +#undef __GMPN_DEFINE_COMPOUND_OPERATOR +#undef __GMP_DEFINE_COMPOUND_OPERATOR + +#undef __GMPQ_DEFINE_COMPOUND_OPERATOR +#undef __GMPF_DEFINE_COMPOUND_OPERATOR + +#undef __GMP_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPZ_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPQ_DEFINE_COMPOUND_OPERATOR_UI +#undef __GMPF_DEFINE_COMPOUND_OPERATOR_UI + +#undef __GMP_DEFINE_INCREMENT_OPERATOR +#undef __GMPZ_DEFINE_INCREMENT_OPERATOR +#undef __GMPQ_DEFINE_INCREMENT_OPERATOR +#undef __GMPF_DEFINE_INCREMENT_OPERATOR + +#undef __GMPXX_CONSTANT + +#endif /* __GMP_PLUSPLUS__ */ diff --git a/include/mpir_x64-windows/lib/mpir.lib b/include/mpir_x64-windows/lib/mpir.lib new file mode 100644 index 0000000..14f7e36 Binary files /dev/null and b/include/mpir_x64-windows/lib/mpir.lib differ diff --git a/include/mpir_x64-windows/share/mpir/copyright b/include/mpir_x64-windows/share/mpir/copyright new file mode 100644 index 0000000..88d61e5 --- /dev/null +++ b/include/mpir_x64-windows/share/mpir/copyright @@ -0,0 +1,847 @@ +COPYING: + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. + + +COPYING.LIB: + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + + diff --git a/lib/hashes/pjw_hash.c b/lib/hashes/pjw_hash.c index 7f51b49..23c8a19 100644 --- a/lib/hashes/pjw_hash.c +++ b/lib/hashes/pjw_hash.c @@ -4,7 +4,7 @@ size_t pjw_hash(Object item, size_t size) { - return elf_hash32(item, size); + return pjw_hash32(item, size); } uint32_t pjw_hash32(Object item, size_t size) diff --git a/src/id0008.c b/src/id0008.c index 3db3999..28e6ac6 100644 --- a/src/id0008.c +++ b/src/id0008.c @@ -39,6 +39,8 @@ int main(void) struct Series series; + buffer[read] = '\0'; + series_from_string(&series, buffer); long long max = series_max_product(&series, 13); diff --git a/src/id0044.c b/src/id0044.c index acc5b2c..8261453 100644 --- a/src/id0044.c +++ b/src/id0044.c @@ -9,7 +9,6 @@ int main(void) { - long time = 0; long min = LONG_MAX; clock_t start = clock(); @@ -19,8 +18,6 @@ int main(void) for (int n = m + 1; n < MAX_SEARCH; n++) { - time++; - long k = (3 * n - 1) * n / 2; long d = k - j; diff --git a/tools/test.cs.ps1 b/tools/test.cs.bat similarity index 73% rename from tools/test.cs.ps1 rename to tools/test.cs.bat index d1bc078..6d2cf11 100644 --- a/tools/test.cs.ps1 +++ b/tools/test.cs.bat @@ -1,4 +1,4 @@ -# Licensed under the MIT License. +:: Licensed under the MIT License. dotnet-script ../src/id0061.csx dotnet-script ../src/id0066.csx diff --git a/tools/test.ps1 b/tools/test.ps1 new file mode 100644 index 0000000..e69de29 diff --git a/tools/test.sh b/tools/test.sh index 65889a1..4a68ec6 100644 --- a/tools/test.sh +++ b/tools/test.sh @@ -2,7 +2,7 @@ for i in {0001..0007}; do - ./../id${i}.o + ${}./../id${i}.o done cat ./../data/id0008.txt | ./../id0008.o