add mpn_sizeinbase.c and its test to MPIR

This commit is contained in:
Brian Gladman 2017-02-09 17:27:01 +00:00
parent 884db8307e
commit 499641998d
4 changed files with 304 additions and 0 deletions

View File

@ -435,6 +435,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpz.next_prime_candidate",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpz.limbs", "mpir-tests\mpz.limbs\mpz.limbs.vcxproj", "{3E2DBDEA-693C-4541-8EC4-BA6FA362CB61}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mpn.sizeinbase", "mpir-tests\mpn.sizeinbase\mpn.sizeinbase.vcxproj", "{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -1663,6 +1665,14 @@ Global
{3E2DBDEA-693C-4541-8EC4-BA6FA362CB61}.Release|Win32.Build.0 = Release|Win32
{3E2DBDEA-693C-4541-8EC4-BA6FA362CB61}.Release|x64.ActiveCfg = Release|x64
{3E2DBDEA-693C-4541-8EC4-BA6FA362CB61}.Release|x64.Build.0 = Release|x64
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Debug|Win32.ActiveCfg = Debug|Win32
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Debug|Win32.Build.0 = Debug|Win32
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Debug|x64.ActiveCfg = Debug|x64
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Debug|x64.Build.0 = Debug|x64
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Release|Win32.ActiveCfg = Release|Win32
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Release|Win32.Build.0 = Release|Win32
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Release|x64.ActiveCfg = Release|x64
{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<RootNamespace>mpn.sizeinbase</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectGuid>{5D6625A7-D775-49B6-9C6C-4FAF440F5F17}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
<Import Project="..\..\test-config.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
<Import Project="..\..\test-config.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
<Import Project="..\..\test-config.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
<Import Project="..\..\test-config.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.21006.1</_ProjectFileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PreBuildEvent>
<Command>cd ..\..\..\build.vc
check_config $(Platform) $(Configuration) 14
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>
</PrecompiledHeader>
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<PreBuildEvent>
<Command>cd ..\..\..\build.vc
check_config $(Platform) $(Configuration) 14
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<PreprocessorDefinitions>_WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>
</PrecompiledHeader>
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<GenerateDebugInformation>Debug</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<PreBuildEvent>
<Command>cd ..\..\..\build.vc
check_config $(Platform) $(Configuration) 14
</Command>
</PreBuildEvent>
<ClCompile>
<Optimization>Full</Optimization>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>
</PrecompiledHeader>
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PreBuildEvent>
<Command>cd ..\..\..\build.vc
check_config $(Platform) $(Configuration) 14
</Command>
</PreBuildEvent>
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Full</Optimization>
<PreprocessorDefinitions>_WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader>
</PrecompiledHeader>
<CompileAs>Default</CompileAs>
<AdditionalIncludeDirectories>$(MPDIR);$(SolutionDir)..\tests</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX64</TargetMachine>
<GenerateDebugInformation>DebugFastLink</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\tests\mpn\t-sizeinbase.c" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\add-test-lib\add-test-lib.vcxproj">
<Project>{a742d3d1-6956-4f85-bfd6-b0e7b477041d}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1830,6 +1830,9 @@ __GMP_DECLSPEC mp_bitcnt_t mpn_scan1 __GMP_PROTO ((mp_srcptr, mp_bitcnt_t)) __GM
#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));

108
tests/mpn/t-sizeinbase.c Normal file
View File

@ -0,0 +1,108 @@
/* Test for sizeinbase function.
Copyright 2014 Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
The GNU MP Library test suite 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.
The GNU MP Library test suite 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
the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */
#include <stdlib.h>
#include <stdio.h>
#include "gmp.h"
#include "gmp-impl.h"
#include "tests.h"
/* Exponents up to 2^SIZE_LOG */
#ifndef SIZE_LOG
#define SIZE_LOG 13
#endif
#ifndef COUNT
#define COUNT 30
#endif
#define MAX_N (1<<SIZE_LOG)
int
main (int argc, char **argv)
{
mp_limb_t a;
mp_ptr pp, scratch;
mp_limb_t max_b;
int count = COUNT;
int test;
gmp_randstate_ptr rands;
TMP_DECL;
if (argc > 1)
{
char *end;
count = strtol (argv[1], &end, 0);
if (*end || count <= 0)
{
fprintf (stderr, "Invalid test count: %s.\n", argv[1]);
return 1;
}
}
tests_start ();
TMP_MARK;
rands = RANDS;
pp = TMP_ALLOC_LIMBS (MAX_N);
scratch = TMP_ALLOC_LIMBS (MAX_N);
max_b = numberof (mp_bases);
ASSERT_ALWAYS (max_b > 62);
ASSERT_ALWAYS (max_b < GMP_NUMB_MAX);
for (a = 2; a < max_b; ++a)
for (test = 0; test < count; ++test)
{
mp_size_t pn;
mp_limb_t exp;
mp_bitcnt_t res;
exp = gmp_urandomm_ui (rands, MAX_N);
pn = mpn_pow_1 (pp, &a, 1, exp, scratch);
res = mpn_sizeinbase (pp, pn, a) - 1;
if ((res < exp) || (res > exp + 1))
{
printf ("ERROR in test %d, base = %d, exp = %d, res = %d\n",
test, (int) a, (int) exp, (int) res);
abort();
}
mpn_sub_1 (pp, pp, pn, CNST_LIMB(1));
pn -= pp[pn-1] == 0;
res = mpn_sizeinbase (pp, pn, a);
if ((res < exp) || (res - 1 > exp))
{
printf ("ERROR in -1 test %d, base = %d, exp = %d, res = %d\n",
test, (int) a, (int) exp, (int) res);
abort();
}
}
TMP_FREE;
tests_end ();
return 0;
}