dbms: purge unused and auto-generated files from double-conversion and vectorclass

This commit is contained in:
Andrey Mironov 2014-12-10 13:25:01 +03:00
parent f3ae946798
commit 736c3e0576
35 changed files with 10 additions and 320861 deletions

10
libs/libdouble-conversion/.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
.sconsign.dblite
*.o
*.obj
msvc/Release/
msvc/Debug/
*.suo
*.opensdf
*.sdf
*.user
*.cmake

View File

@ -1,2 +0,0 @@
set(double-conversion_INCLUDE_DIRS
"/home/hertz/Development/metrika-core/metrica/src/libs/libdouble-conversion/src")

View File

@ -1,17 +0,0 @@
# - Config file for the double-conversion package
# It defines the following variables
# double-conversion_INCLUDE_DIRS
# double-conversion_LIBRARIES
get_filename_component(double-conversion_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
if(EXISTS "${double-conversion_CMAKE_DIR}/CMakeCache.txt")
include("${double-conversion_CMAKE_DIR}/double-conversionBuildTreeSettings.cmake")
else()
set(double-conversion_INCLUDE_DIRS
"${double-conversion_CMAKE_DIR}/../../..//include/double-conversion")
endif()
include("${double-conversion_CMAKE_DIR}/double-conversionLibraryDepends.cmake")
set(double-conversion_LIBRARIES double-conversion)

View File

@ -1,11 +0,0 @@
set(PACKAGE_VERSION "2.0.1")
# Check whether the requested PACKAGE_FIND_VERSION is compatible
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()

View File

@ -1,56 +0,0 @@
# Generated by CMake 2.8.12.2
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget double-conversion)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
# Create imported target double-conversion
add_library(double-conversion STATIC IMPORTED)
# Import target "double-conversion" for configuration "RELWITHDEBINFO"
set_property(TARGET double-conversion APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(double-conversion PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELWITHDEBINFO "CXX"
IMPORTED_LOCATION_RELWITHDEBINFO "/home/hertz/Development/metrika-core/metrica/src/libs/libdouble-conversion/src/libdouble-conversion.a"
)
# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)

View File

@ -1,38 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "double-conversion", "double-conversion.vcxproj", "{6863544A-0CE8-4CA9-A132-74116FD9D9BB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "run_tests", "run_tests\run_tests.vcxproj", "{5619CA2B-6D39-4984-BE37-7580BBBD2139}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Debug|Win32.ActiveCfg = Debug|Win32
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Debug|Win32.Build.0 = Debug|Win32
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Debug|x64.ActiveCfg = Debug|x64
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Debug|x64.Build.0 = Debug|x64
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Release|Win32.ActiveCfg = Release|Win32
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Release|Win32.Build.0 = Release|Win32
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Release|x64.ActiveCfg = Release|x64
{6863544A-0CE8-4CA9-A132-74116FD9D9BB}.Release|x64.Build.0 = Release|x64
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Debug|Win32.ActiveCfg = Debug|Win32
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Debug|Win32.Build.0 = Debug|Win32
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Debug|x64.ActiveCfg = Debug|x64
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Debug|x64.Build.0 = Debug|x64
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Release|Win32.ActiveCfg = Release|Win32
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Release|Win32.Build.0 = Release|Win32
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Release|x64.ActiveCfg = Release|x64
{5619CA2B-6D39-4984-BE37-7580BBBD2139}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -1,174 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.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">
<ProjectGuid>{6863544A-0CE8-4CA9-A132-74116FD9D9BB}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>doubleconversion</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</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')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</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')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\src\bignum-dtoa.cc" />
<ClCompile Include="..\src\bignum.cc" />
<ClCompile Include="..\src\cached-powers.cc" />
<ClCompile Include="..\src\diy-fp.cc" />
<ClCompile Include="..\src\double-conversion.cc" />
<ClCompile Include="..\src\fast-dtoa.cc" />
<ClCompile Include="..\src\fixed-dtoa.cc" />
<ClCompile Include="..\src\strtod.cc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\bignum-dtoa.h" />
<ClInclude Include="..\src\bignum.h" />
<ClInclude Include="..\src\cached-powers.h" />
<ClInclude Include="..\src\diy-fp.h" />
<ClInclude Include="..\src\double-conversion.h" />
<ClInclude Include="..\src\fast-dtoa.h" />
<ClInclude Include="..\src\fixed-dtoa.h" />
<ClInclude Include="..\src\ieee.h" />
<ClInclude Include="..\src\strtod.h" />
<ClInclude Include="..\src\utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,75 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\bignum.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\bignum-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\cached-powers.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\diy-fp.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\double-conversion.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\fast-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\fixed-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\strtod.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\bignum.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\bignum-dtoa.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\cached-powers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\diy-fp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\double-conversion.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\fast-dtoa.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\fixed-dtoa.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\ieee.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\strtod.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\src\utils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -1,185 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.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">
<ProjectGuid>{5619CA2B-6D39-4984-BE37-7580BBBD2139}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>run_tests</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</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')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</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')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\run_tests\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\run_tests\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\run_tests\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(Platform)\</OutDir>
<IntDir>$(SolutionDir)$(Configuration)\$(Platform)\intermediate\run_tests\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)..\src</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\test\cctest\cctest.cc" />
<ClCompile Include="..\..\test\cctest\gay-fixed.cc" />
<ClCompile Include="..\..\test\cctest\gay-precision.cc" />
<ClCompile Include="..\..\test\cctest\gay-shortest-single.cc" />
<ClCompile Include="..\..\test\cctest\gay-shortest.cc" />
<ClCompile Include="..\..\test\cctest\test-bignum-dtoa.cc" />
<ClCompile Include="..\..\test\cctest\test-bignum.cc" />
<ClCompile Include="..\..\test\cctest\test-conversions.cc" />
<ClCompile Include="..\..\test\cctest\test-diy-fp.cc" />
<ClCompile Include="..\..\test\cctest\test-dtoa.cc" />
<ClCompile Include="..\..\test\cctest\test-fast-dtoa.cc" />
<ClCompile Include="..\..\test\cctest\test-fixed-dtoa.cc" />
<ClCompile Include="..\..\test\cctest\test-ieee.cc" />
<ClCompile Include="..\..\test\cctest\test-strtod.cc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\test\cctest\cctest.h" />
<ClInclude Include="..\..\test\cctest\checks.h" />
<ClInclude Include="..\..\test\cctest\gay-fixed.h" />
<ClInclude Include="..\..\test\cctest\gay-precision.h" />
<ClInclude Include="..\..\test\cctest\gay-shortest-single.h" />
<ClInclude Include="..\..\test\cctest\gay-shortest.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\double-conversion.vcxproj">
<Project>{6863544a-0ce8-4ca9-a132-74116fd9d9bb}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,81 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\test\cctest\cctest.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\gay-fixed.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\gay-precision.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\gay-shortest.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\gay-shortest-single.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-bignum.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-bignum-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-conversions.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-diy-fp.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-fast-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-fixed-dtoa.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-ieee.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\test\cctest\test-strtod.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\test\cctest\cctest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test\cctest\checks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test\cctest\gay-fixed.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test\cctest\gay-precision.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test\cctest\gay-shortest.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\test\cctest\gay-shortest-single.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,11 +0,0 @@
@echo off
setlocal enabledelayedexpansion
setlocal enableextensions
for /f useback %%f in (`Release\x64\run_tests.exe --list`) do (
set var=%%f
if "x!var:~-1!" == "x<" (
set var=!var:~0,-1!
)
Release\x64\run_tests !var!
)

View File

@ -1,17 +0,0 @@
double_conversion_test_sources = [
'cctest.cc',
'gay-fixed.cc',
'gay-precision.cc',
'gay-shortest.cc',
'gay-shortest-single.cc',
'test-bignum.cc',
'test-bignum-dtoa.cc',
'test-conversions.cc',
'test-diy-fp.cc',
'test-dtoa.cc',
'test-fast-dtoa.cc',
'test-fixed-dtoa.cc',
'test-ieee.cc',
'test-strtod.cc',
]
Return('double_conversion_test_sources')

View File

@ -1,124 +0,0 @@
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cctest.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
CcTest* CcTest::last_ = NULL;
CcTest::CcTest(TestFunction* callback, const char* test_file,
const char* test_name, const char* test_dependency,
bool test_is_enabled)
: callback_(callback), name_(test_name), dependency_(test_dependency),
prev_(last_) {
// Find the base name of this test (const_cast required on Windows).
char *basename = strrchr(const_cast<char *>(test_file), '/');
if (!basename) {
basename = strrchr(const_cast<char *>(test_file), '\\');
}
if (!basename) {
basename = strdup(test_file);
} else {
basename = strdup(basename + 1);
}
// Drop the extension, if there is one.
char *extension = strrchr(basename, '.');
if (extension) *extension = 0;
// Install this test in the list of tests
file_ = basename;
enabled_ = test_is_enabled;
prev_ = last_;
last_ = this;
}
static void PrintTestList(CcTest* current) {
if (current == NULL) return;
PrintTestList(current->prev());
if (current->dependency() != NULL) {
printf("%s/%s<%s\n",
current->file(), current->name(), current->dependency());
} else {
printf("%s/%s<\n", current->file(), current->name());
}
}
int main(int argc, char* argv[]) {
int tests_run = 0;
bool print_run_count = true;
for (int i = 1; i < argc; i++) {
char* arg = argv[i];
if (strcmp(arg, "--list") == 0) {
PrintTestList(CcTest::last());
print_run_count = false;
} else {
char* arg_copy = strdup(arg);
char* testname = strchr(arg_copy, '/');
if (testname) {
// Split the string in two by nulling the slash and then run
// exact matches.
*testname = 0;
char* file = arg_copy;
char* name = testname + 1;
CcTest* test = CcTest::last();
while (test != NULL) {
if (test->enabled()
&& strcmp(test->file(), file) == 0
&& strcmp(test->name(), name) == 0) {
test->Run();
tests_run++;
}
test = test->prev();
}
} else {
// Run all tests with the specified file or test name.
char* file_or_name = arg_copy;
CcTest* test = CcTest::last();
while (test != NULL) {
if (test->enabled()
&& (strcmp(test->file(), file_or_name) == 0
|| strcmp(test->name(), file_or_name) == 0)) {
test->Run();
tests_run++;
}
test = test->prev();
}
}
delete[] arg_copy;
}
}
if (print_run_count && tests_run != 1)
printf("Ran %i tests.\n", tests_run);
return 0;
}

View File

@ -1,141 +0,0 @@
// Copyright 2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef CCTEST_H_
#define CCTEST_H_
#include <stdio.h>
#include <string.h>
#include "utils.h"
#ifndef TEST
#define TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true); \
static void Test##Name()
#endif
#ifndef DEPENDENT_TEST
#define DEPENDENT_TEST(Name, Dep) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, #Dep, true); \
static void Test##Name()
#endif
#ifndef DISABLED_TEST
#define DISABLED_TEST(Name) \
static void Test##Name(); \
CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, false); \
static void Test##Name()
#endif
#define CHECK(condition) CheckHelper(__FILE__, __LINE__, #condition, condition)
#define CHECK_GE(a, b) CHECK((a) >= (b))
static inline void CheckHelper(const char* file,
int line,
const char* source,
bool condition) {
if (!condition) {
printf("%s:%d:\n CHECK(%s) failed\n", file, line, source);
abort();
}
}
#define CHECK_EQ(a, b) CheckEqualsHelper(__FILE__, __LINE__, #a, a, #b, b)
static inline void CheckEqualsHelper(const char* file, int line,
const char* expected_source,
const char* expected,
const char* value_source,
const char* value) {
if ((expected == NULL && value != NULL) ||
(expected != NULL && value == NULL) ||
(expected != NULL && value != NULL && strcmp(expected, value) != 0)) {
printf("%s:%d:\n CHECK_EQ(%s, %s) failed\n"
"# Expected: %s\n"
"# Found: %s\n",
file, line, expected_source, value_source, expected, value);
abort();
}
}
static inline void CheckEqualsHelper(const char* file, int line,
const char* expected_source,
int expected,
const char* value_source,
int value) {
if (expected != value) {
printf("%s:%d:\n CHECK_EQ(%s, %s) failed\n"
"# Expected: %d\n"
"# Found: %d\n",
file, line, expected_source, value_source, expected, value);
abort();
}
}
static inline void CheckEqualsHelper(const char* file, int line,
const char* expected_source,
double expected,
const char* value_source,
double value) {
// If expected and value are NaNs then expected != value.
if (expected != value && (expected == expected || value == value)) {
printf("%s:%d:\n CHECK_EQ(%s, %s) failed\n"
"# Expected: %.30e\n"
"# Found: %.30e\n",
file, line, expected_source, value_source, expected, value);
abort();
}
}
class CcTest {
public:
typedef void (TestFunction)();
CcTest(TestFunction* callback, const char* file, const char* name,
const char* dependency, bool enabled);
void Run() { callback_(); }
static int test_count();
static CcTest* last() { return last_; }
CcTest* prev() { return prev_; }
const char* file() { return file_; }
const char* name() { return name_; }
const char* dependency() { return dependency_; }
bool enabled() { return enabled_; }
private:
TestFunction* callback_;
const char* file_;
const char* name_;
const char* dependency_;
bool enabled_;
static CcTest* last_;
CcTest* prev_;
};
#endif // ifndef CCTEST_H_

View File

@ -1,314 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_CHECKS_H_
#define V8_CHECKS_H_
#include <string.h>
#include "flags.h"
extern "C" void V8_Fatal(const char* file, int line, const char* format, ...);
void API_Fatal(const char* location, const char* format, ...);
// The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
// development, but they should not be relied on in the final product.
#ifdef DEBUG
#define FATAL(msg) \
V8_Fatal(__FILE__, __LINE__, "%s", (msg))
#define UNIMPLEMENTED() \
V8_Fatal(__FILE__, __LINE__, "unimplemented code")
#define UNREACHABLE() \
V8_Fatal(__FILE__, __LINE__, "unreachable code")
#else
#define FATAL(msg) \
V8_Fatal("", 0, "%s", (msg))
#define UNIMPLEMENTED() \
V8_Fatal("", 0, "unimplemented code")
#define UNREACHABLE() ((void) 0)
#endif
// Used by the CHECK macro -- should not be called directly.
static inline void CheckHelper(const char* file,
int line,
const char* source,
bool condition) {
if (!condition)
V8_Fatal(file, line, "CHECK(%s) failed", source);
}
// The CHECK macro checks that the given condition is true; if not, it
// prints a message to stderr and aborts.
#define CHECK(condition) CheckHelper(__FILE__, __LINE__, #condition, condition)
// Helper function used by the CHECK_EQ function when given int
// arguments. Should not be called directly.
static inline void CheckEqualsHelper(const char* file, int line,
const char* expected_source, int expected,
const char* value_source, int value) {
if (expected != value) {
V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# Expected: %i\n# Found: %i",
expected_source, value_source, expected, value);
}
}
// Helper function used by the CHECK_EQ function when given int64_t
// arguments. Should not be called directly.
static inline void CheckEqualsHelper(const char* file, int line,
const char* expected_source,
int64_t expected,
const char* value_source,
int64_t value) {
if (expected != value) {
// Print int64_t values in hex, as two int32s,
// to avoid platform-dependencies.
V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n#"
" Expected: 0x%08x%08x\n# Found: 0x%08x%08x",
expected_source, value_source,
static_cast<uint32_t>(expected >> 32),
static_cast<uint32_t>(expected),
static_cast<uint32_t>(value >> 32),
static_cast<uint32_t>(value));
}
}
// Helper function used by the CHECK_NE function when given int
// arguments. Should not be called directly.
static inline void CheckNonEqualsHelper(const char* file,
int line,
const char* unexpected_source,
int unexpected,
const char* value_source,
int value) {
if (unexpected == value) {
V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %i",
unexpected_source, value_source, value);
}
}
// Helper function used by the CHECK function when given string
// arguments. Should not be called directly.
static inline void CheckEqualsHelper(const char* file,
int line,
const char* expected_source,
const char* expected,
const char* value_source,
const char* value) {
if ((expected == NULL && value != NULL) ||
(expected != NULL && value == NULL) ||
(expected != NULL && value != NULL && strcmp(expected, value) != 0)) {
V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# Expected: %s\n# Found: %s",
expected_source, value_source, expected, value);
}
}
static inline void CheckNonEqualsHelper(const char* file,
int line,
const char* expected_source,
const char* expected,
const char* value_source,
const char* value) {
if (expected == value ||
(expected != NULL && value != NULL && strcmp(expected, value) == 0)) {
V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %s",
expected_source, value_source, value);
}
}
// Helper function used by the CHECK function when given pointer
// arguments. Should not be called directly.
static inline void CheckEqualsHelper(const char* file,
int line,
const char* expected_source,
const void* expected,
const char* value_source,
const void* value) {
if (expected != value) {
V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# Expected: %p\n# Found: %p",
expected_source, value_source,
expected, value);
}
}
static inline void CheckNonEqualsHelper(const char* file,
int line,
const char* expected_source,
const void* expected,
const char* value_source,
const void* value) {
if (expected == value) {
V8_Fatal(file, line, "CHECK_NE(%s, %s) failed\n# Value: %p",
expected_source, value_source, value);
}
}
// Helper function used by the CHECK function when given floating
// point arguments. Should not be called directly.
static inline void CheckEqualsHelper(const char* file,
int line,
const char* expected_source,
double expected,
const char* value_source,
double value) {
// Force values to 64 bit memory to truncate 80 bit precision on IA32.
volatile double* exp = new double[1];
*exp = expected;
volatile double* val = new double[1];
*val = value;
if (*exp != *val) {
V8_Fatal(file, line,
"CHECK_EQ(%s, %s) failed\n# Expected: %f\n# Found: %f",
expected_source, value_source, *exp, *val);
}
delete[] exp;
delete[] val;
}
static inline void CheckNonEqualsHelper(const char* file,
int line,
const char* expected_source,
double expected,
const char* value_source,
double value) {
// Force values to 64 bit memory to truncate 80 bit precision on IA32.
volatile double* exp = new double[1];
*exp = expected;
volatile double* val = new double[1];
*val = value;
if (*exp == *val) {
V8_Fatal(file, line,
"CHECK_NE(%s, %s) failed\n# Value: %f",
expected_source, value_source, *val);
}
delete[] exp;
delete[] val;
}
namespace v8 {
class Value;
template <class T> class Handle;
}
void CheckNonEqualsHelper(const char* file,
int line,
const char* unexpected_source,
v8::Handle<v8::Value> unexpected,
const char* value_source,
v8::Handle<v8::Value> value);
void CheckEqualsHelper(const char* file,
int line,
const char* expected_source,
v8::Handle<v8::Value> expected,
const char* value_source,
v8::Handle<v8::Value> value);
#define CHECK_EQ(expected, value) CheckEqualsHelper(__FILE__, __LINE__, \
#expected, expected, #value, value)
#define CHECK_NE(unexpected, value) CheckNonEqualsHelper(__FILE__, __LINE__, \
#unexpected, unexpected, #value, value)
#define CHECK_GT(a, b) CHECK((a) > (b))
#define CHECK_GE(a, b) CHECK((a) >= (b))
// This is inspired by the static assertion facility in boost. This
// is pretty magical. If it causes you trouble on a platform you may
// find a fix in the boost code.
template <bool> class StaticAssertion;
template <> class StaticAssertion<true> { };
// This macro joins two tokens. If one of the tokens is a macro the
// helper call causes it to be resolved before joining.
#define SEMI_STATIC_JOIN(a, b) SEMI_STATIC_JOIN_HELPER(a, b)
#define SEMI_STATIC_JOIN_HELPER(a, b) a##b
// Causes an error during compilation of the condition is not
// statically known to be true. It is formulated as a typedef so that
// it can be used wherever a typedef can be used. Beware that this
// actually causes each use to introduce a new defined type with a
// name depending on the source line.
template <int> class StaticAssertionHelper { };
#define STATIC_CHECK(test) \
typedef \
StaticAssertionHelper<sizeof(StaticAssertion<static_cast<bool>(test)>)> \
SEMI_STATIC_JOIN(__StaticAssertTypedef__, __LINE__)
// The ASSERT macro is equivalent to CHECK except that it only
// generates code in debug builds.
#ifdef DEBUG
#define ASSERT_RESULT(expr) CHECK(expr)
#define ASSERT(condition) CHECK(condition)
#define ASSERT_EQ(v1, v2) CHECK_EQ(v1, v2)
#define ASSERT_NE(v1, v2) CHECK_NE(v1, v2)
#define ASSERT_GE(v1, v2) CHECK_GE(v1, v2)
#define SLOW_ASSERT(condition) if (FLAG_enable_slow_asserts) CHECK(condition)
#else
#define ASSERT_RESULT(expr) (expr)
#define ASSERT(condition) ((void) 0)
#define ASSERT_EQ(v1, v2) ((void) 0)
#define ASSERT_NE(v1, v2) ((void) 0)
#define ASSERT_GE(v1, v2) ((void) 0)
#define SLOW_ASSERT(condition) ((void) 0)
#endif
// Static asserts has no impact on runtime performance, so they can be
// safely enabled in release mode. Moreover, the ((void) 0) expression
// obeys different syntax rules than typedef's, e.g. it can't appear
// inside class declaration, this leads to inconsistency between debug
// and release compilation modes behaviour.
#define STATIC_ASSERT(test) STATIC_CHECK(test)
#define ASSERT_TAG_ALIGNED(address) \
ASSERT((reinterpret_cast<intptr_t>(address) & kHeapObjectTagMask) == 0)
#define ASSERT_SIZE_TAG_ALIGNED(size) ASSERT((size & kHeapObjectTagMask) == 0)
#define ASSERT_NOT_NULL(p) ASSERT_NE(NULL, p)
#endif // V8_CHECKS_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GAY_FIXED_H_
#define GAY_FIXED_H_
namespace double_conversion {
struct PrecomputedFixed {
double v;
int number_digits;
const char* representation;
int decimal_point;
};
// Returns precomputed values of dtoa. The strings have been generated using
// Gay's dtoa in mode "fixed".
Vector<const PrecomputedFixed> PrecomputedFixedRepresentations();
} // namespace double_conversion
#endif // GAY_FIXED_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,46 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GAY_PRECISION_H_
#define GAY_PRECISION_H_
namespace double_conversion {
struct PrecomputedPrecision {
double v;
int number_digits;
const char* representation;
int decimal_point;
};
// Returns precomputed values of dtoa. The strings have been generated using
// Gay's dtoa in mode "precision".
Vector<const PrecomputedPrecision> PrecomputedPrecisionRepresentations();
} // namespace double_conversion
#endif // GAY_PRECISION_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +0,0 @@
// Copyright 2011, the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GAY_SHORTEST_SINGLE_H_
#define GAY_SHORTEST_SINGLE_H_
namespace double_conversion {
struct PrecomputedShortestSingle {
float v;
const char* representation;
int decimal_point;
};
Vector<const PrecomputedShortestSingle>
PrecomputedShortestSingleRepresentations();
} // namespace double_conversion
#endif // GAY_SHORTEST_SINGLE_H_

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef GAY_SHORTEST_H_
#define GAY_SHORTEST_H_
namespace double_conversion {
struct PrecomputedShortest {
double v;
const char* representation;
int decimal_point;
};
Vector<const PrecomputedShortest> PrecomputedShortestRepresentations();
} // namespace double_conversion
#endif // GAY_SHORTEST_H_

View File

@ -1,395 +0,0 @@
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include "bignum-dtoa.h"
#include "cctest.h"
#include "gay-fixed.h"
#include "gay-precision.h"
#include "gay-shortest.h"
#include "gay-shortest-single.h"
#include "ieee.h"
#include "utils.h"
using namespace double_conversion;
// Removes trailing '0' digits.
// Can return the empty string if all digits are 0.
static void TrimRepresentation(Vector<char> representation) {
int len = strlen(representation.start());
int i;
for (i = len - 1; i >= 0; --i) {
if (representation[i] != '0') break;
}
representation[i + 1] = '\0';
}
static const int kBufferSize = 100;
TEST(BignumDtoaVariousDoubles) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
BignumDtoa(1.0, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
BignumDtoa(1.0, BIGNUM_DTOA_FIXED, 3, buffer, &length, &point);
CHECK_GE(3, length - point);
TrimRepresentation(buffer);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
BignumDtoa(1.0, BIGNUM_DTOA_PRECISION, 3, buffer, &length, &point);
CHECK_GE(3, length);
TrimRepresentation(buffer);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
BignumDtoa(1.5, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
BignumDtoa(1.5, BIGNUM_DTOA_FIXED, 10, buffer, &length, &point);
CHECK_GE(10, length - point);
TrimRepresentation(buffer);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
BignumDtoa(1.5, BIGNUM_DTOA_PRECISION, 10, buffer, &length, &point);
CHECK_GE(10, length);
TrimRepresentation(buffer);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
double min_double = 5e-324;
BignumDtoa(min_double, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point);
BignumDtoa(min_double, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
CHECK_GE(5, length - point);
TrimRepresentation(buffer);
CHECK_EQ("", buffer.start());
BignumDtoa(min_double, BIGNUM_DTOA_PRECISION, 5, buffer, &length, &point);
CHECK_GE(5, length);
TrimRepresentation(buffer);
CHECK_EQ("49407", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
BignumDtoa(max_double, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point);
BignumDtoa(max_double, BIGNUM_DTOA_PRECISION, 7, buffer, &length, &point);
CHECK_GE(7, length);
TrimRepresentation(buffer);
CHECK_EQ("1797693", buffer.start());
CHECK_EQ(309, point);
BignumDtoa(4294967272.0, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(4294967272.0, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
CHECK_EQ("429496727200000", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(4294967272.0, BIGNUM_DTOA_PRECISION, 14, buffer, &length, &point);
CHECK_GE(14, length);
TrimRepresentation(buffer);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point);
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_PRECISION, 20,
buffer, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("41855804968213567225", buffer.start());
CHECK_EQ(299, point);
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point);
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_PRECISION, 1,
buffer, &length, &point);
CHECK_GE(1, length);
TrimRepresentation(buffer);
CHECK_EQ("6", buffer.start());
CHECK_EQ(-308, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_FIXED, 2,
buffer, &length, &point);
CHECK_GE(2, length - point);
TrimRepresentation(buffer);
CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(2147483648.0, BIGNUM_DTOA_PRECISION, 5,
buffer, &length, &point);
CHECK_GE(5, length);
TrimRepresentation(buffer);
CHECK_EQ("21475", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(299, point);
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_PRECISION, 10,
buffer, &length, &point);
CHECK_GE(10, length);
TrimRepresentation(buffer);
CHECK_EQ("35844466", buffer.start());
CHECK_EQ(299, point);
uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
double v = Double(smallest_normal64).value();
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 20, buffer, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("22250738585072013831", buffer.start());
CHECK_EQ(-307, point);
uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
v = Double(largest_denormal64).value();
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point);
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 20, buffer, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("2225073858507200889", buffer.start());
CHECK_EQ(-307, point);
BignumDtoa(4128420500802942e-24, BIGNUM_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK_EQ("4128420500802942", buffer.start());
CHECK_EQ(-8, point);
v = 3.9292015898194142585311918e-10;
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ("39292015898194143", buffer.start());
v = 4194304.0;
BignumDtoa(v, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
CHECK_GE(5, length - point);
TrimRepresentation(buffer);
CHECK_EQ("4194304", buffer.start());
v = 3.3161339052167390562200598e-237;
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 19, buffer, &length, &point);
CHECK_GE(19, length);
TrimRepresentation(buffer);
CHECK_EQ("3316133905216739056", buffer.start());
CHECK_EQ(-236, point);
v = 7.9885183916008099497815232e+191;
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 4, buffer, &length, &point);
CHECK_GE(4, length);
TrimRepresentation(buffer);
CHECK_EQ("7989", buffer.start());
CHECK_EQ(192, point);
v = 1.0000000000000012800000000e+17;
BignumDtoa(v, BIGNUM_DTOA_FIXED, 1, buffer, &length, &point);
CHECK_GE(1, length - point);
TrimRepresentation(buffer);
CHECK_EQ("100000000000000128", buffer.start());
CHECK_EQ(18, point);
}
TEST(BignumDtoaShortestVariousFloats) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
float min_float = 1e-45f;
BignumDtoa(min_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("1", buffer.start());
CHECK_EQ(-44, point);
float max_float = 3.4028234e38f;
BignumDtoa(max_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("34028235", buffer.start());
CHECK_EQ(39, point);
BignumDtoa(4294967272.0f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("42949673", buffer.start());
CHECK_EQ(10, point);
BignumDtoa(3.32306998946228968226e+35f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("332307", buffer.start());
CHECK_EQ(36, point);
BignumDtoa(1.2341e-41f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("12341", buffer.start());
CHECK_EQ(-40, point);
BignumDtoa(3.3554432e7, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("33554432", buffer.start());
CHECK_EQ(8, point);
BignumDtoa(3.26494756798464e14f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("32649476", buffer.start());
CHECK_EQ(15, point);
BignumDtoa(3.91132223637771935344e37f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK_EQ("39113222", buffer.start());
CHECK_EQ(38, point);
uint32_t smallest_normal32 = 0x00800000;
double v = Single(smallest_normal32).value();
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
CHECK_EQ("11754944", buffer.start());
CHECK_EQ(-37, point);
uint32_t largest_denormal32 = 0x007FFFFF;
v = Single(largest_denormal32).value();
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
CHECK_EQ("11754942", buffer.start());
CHECK_EQ(-37, point);
}
TEST(BignumDtoaGayShortest) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
Vector<const PrecomputedShortest> precomputed =
PrecomputedShortestRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortest current_test = precomputed[i];
double v = current_test.v;
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(BignumDtoaGayShortestSingle) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
Vector<const PrecomputedShortestSingle> precomputed =
PrecomputedShortestSingleRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortestSingle current_test = precomputed[i];
float v = current_test.v;
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(BignumDtoaGayFixed) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
Vector<const PrecomputedFixed> precomputed =
PrecomputedFixedRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedFixed current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
BignumDtoa(v, BIGNUM_DTOA_FIXED, number_digits, buffer, &length, &point);
CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length - point);
TrimRepresentation(buffer);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(BignumDtoaGayPrecision) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
Vector<const PrecomputedPrecision> precomputed =
PrecomputedPrecisionRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedPrecision current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
BignumDtoa(v, BIGNUM_DTOA_PRECISION, number_digits,
buffer, &length, &point);
CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length);
TrimRepresentation(buffer);
CHECK_EQ(current_test.representation, buffer.start());
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,65 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
#include <stdlib.h>
#include "cctest.h"
#include "diy-fp.h"
#include "utils.h"
using namespace double_conversion;
TEST(Subtract) {
DiyFp diy_fp1 = DiyFp(3, 0);
DiyFp diy_fp2 = DiyFp(1, 0);
DiyFp diff = DiyFp::Minus(diy_fp1, diy_fp2);
CHECK(2 == diff.f()); // NOLINT
CHECK_EQ(0, diff.e());
diy_fp1.Subtract(diy_fp2);
CHECK(2 == diy_fp1.f()); // NOLINT
CHECK_EQ(0, diy_fp1.e());
}
TEST(Multiply) {
DiyFp diy_fp1 = DiyFp(3, 0);
DiyFp diy_fp2 = DiyFp(2, 0);
DiyFp product = DiyFp::Times(diy_fp1, diy_fp2);
CHECK(0 == product.f()); // NOLINT
CHECK_EQ(64, product.e());
diy_fp1.Multiply(diy_fp2);
CHECK(0 == diy_fp1.f()); // NOLINT
CHECK_EQ(64, diy_fp1.e());
diy_fp1 = DiyFp(UINT64_2PART_C(0x80000000, 00000000), 11);
diy_fp2 = DiyFp(2, 13);
product = DiyFp::Times(diy_fp1, diy_fp2);
CHECK(1 == product.f()); // NOLINT
CHECK_EQ(11 + 13 + 64, product.e());
// Test rounding.
diy_fp1 = DiyFp(UINT64_2PART_C(0x80000000, 00000001), 11);
diy_fp2 = DiyFp(1, 13);
product = DiyFp::Times(diy_fp1, diy_fp2);
CHECK(1 == product.f()); // NOLINT
CHECK_EQ(11 + 13 + 64, product.e());
diy_fp1 = DiyFp(UINT64_2PART_C(0x7fffffff, ffffffff), 11);
diy_fp2 = DiyFp(1, 13);
product = DiyFp::Times(diy_fp1, diy_fp2);
CHECK(0 == product.f()); // NOLINT
CHECK_EQ(11 + 13 + 64, product.e());
// Halfway cases are allowed to round either way. So don't check for it.
// Big numbers.
diy_fp1 = DiyFp(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF), 11);
diy_fp2 = DiyFp(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF), 13);
// 128bit result: 0xfffffffffffffffe0000000000000001
product = DiyFp::Times(diy_fp1, diy_fp2);
CHECK(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFe) == product.f());
CHECK_EQ(11 + 13 + 64, product.e());
}

View File

@ -1,507 +0,0 @@
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include "double-conversion.h"
#include "cctest.h"
#include "gay-fixed.h"
#include "gay-precision.h"
#include "gay-shortest.h"
#include "gay-shortest-single.h"
#include "ieee.h"
using namespace double_conversion;
enum DtoaMode {
SHORTEST,
SHORTEST_SINGLE,
FIXED,
PRECISION
};
static void DoubleToAscii(double v, DtoaMode test_mode, int requested_digits,
Vector<char> buffer, bool* sign, int* length,
int* point) {
DoubleToStringConverter::DtoaMode mode = DoubleToStringConverter::SHORTEST;
switch (test_mode) {
case SHORTEST: mode = DoubleToStringConverter::SHORTEST; break;
case SHORTEST_SINGLE:
mode = DoubleToStringConverter::SHORTEST_SINGLE;
break;
case FIXED: mode = DoubleToStringConverter::FIXED; break;
case PRECISION: mode = DoubleToStringConverter::PRECISION; break;
}
DoubleToStringConverter::DoubleToAscii(v, mode, requested_digits,
buffer.start(), buffer.length(),
sign, length, point);
}
// Removes trailing '0' digits.
static void TrimRepresentation(Vector<char> representation) {
int len = strlen(representation.start());
int i;
for (i = len - 1; i >= 0; --i) {
if (representation[i] != '0') break;
}
representation[i + 1] = '\0';
}
static const int kBufferSize = 100;
TEST(DtoaVariousDoubles) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
bool sign;
DoubleToAscii(0.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("0", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(0.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("0", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(0.0, FIXED, 2, buffer, &sign, &length, &point);
CHECK_EQ(1, length);
CHECK_EQ("0", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(0.0, PRECISION, 3, buffer, &sign, &length, &point);
CHECK_EQ(1, length);
CHECK_EQ("0", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.0, FIXED, 3, buffer, &sign, &length, &point);
CHECK_GE(3, length - point);
TrimRepresentation(buffer);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.0, PRECISION, 3, buffer, &sign, &length, &point);
CHECK_GE(3, length);
TrimRepresentation(buffer);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.5, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.5f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.5, FIXED, 10, buffer, &sign, &length, &point);
CHECK_GE(10, length - point);
TrimRepresentation(buffer);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
DoubleToAscii(1.5, PRECISION, 10, buffer, &sign, &length, &point);
CHECK_GE(10, length);
TrimRepresentation(buffer);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
double min_double = 5e-324;
DoubleToAscii(min_double, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point);
float min_float = 1e-45f;
DoubleToAscii(min_float, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("1", buffer.start());
CHECK_EQ(-44, point);
DoubleToAscii(min_double, FIXED, 5, buffer, &sign, &length, &point);
CHECK_GE(5, length - point);
TrimRepresentation(buffer);
CHECK_EQ("", buffer.start());
CHECK_GE(-5, point);
DoubleToAscii(min_double, PRECISION, 5, buffer, &sign, &length, &point);
CHECK_GE(5, length);
TrimRepresentation(buffer);
CHECK_EQ("49407", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
DoubleToAscii(max_double, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point);
float max_float = 3.4028234e38f;
DoubleToAscii(max_float, SHORTEST_SINGLE, 0,
buffer, &sign, &length, &point);
CHECK_EQ("34028235", buffer.start());
CHECK_EQ(39, point);
DoubleToAscii(max_double, PRECISION, 7, buffer, &sign, &length, &point);
CHECK_GE(7, length);
TrimRepresentation(buffer);
CHECK_EQ("1797693", buffer.start());
CHECK_EQ(309, point);
DoubleToAscii(4294967272.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(4294967272.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("42949673", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(4294967272.0, FIXED, 5, buffer, &sign, &length, &point);
CHECK_GE(5, length - point);
TrimRepresentation(buffer);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(4294967272.0, PRECISION, 14,
buffer, &sign, &length, &point);
CHECK_GE(14, length);
TrimRepresentation(buffer);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(4.1855804968213567e298, SHORTEST, 0,
buffer, &sign, &length, &point);
CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point);
DoubleToAscii(4.1855804968213567e298, PRECISION, 20,
buffer, &sign, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("41855804968213567225", buffer.start());
CHECK_EQ(299, point);
DoubleToAscii(5.5626846462680035e-309, SHORTEST, 0,
buffer, &sign, &length, &point);
CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point);
DoubleToAscii(5.5626846462680035e-309, PRECISION, 1,
buffer, &sign, &length, &point);
CHECK_GE(1, length);
TrimRepresentation(buffer);
CHECK_EQ("6", buffer.start());
CHECK_EQ(-308, point);
DoubleToAscii(-2147483648.0, SHORTEST, 0,
buffer, &sign, &length, &point);
CHECK_EQ(1, sign);
CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(-2147483648.0, SHORTEST_SINGLE, 0,
buffer, &sign, &length, &point);
CHECK_EQ(1, sign);
CHECK_EQ("21474836", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(-2147483648.0, FIXED, 2, buffer, &sign, &length, &point);
CHECK_GE(2, length - point);
TrimRepresentation(buffer);
CHECK_EQ(1, sign);
CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(-2147483648.0, PRECISION, 5,
buffer, &sign, &length, &point);
CHECK_GE(5, length);
TrimRepresentation(buffer);
CHECK_EQ(1, sign);
CHECK_EQ("21475", buffer.start());
CHECK_EQ(10, point);
DoubleToAscii(-3.5844466002796428e+298, SHORTEST, 0,
buffer, &sign, &length, &point);
CHECK_EQ(1, sign);
CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(299, point);
DoubleToAscii(-3.5844466002796428e+298, PRECISION, 10,
buffer, &sign, &length, &point);
CHECK_EQ(1, sign);
CHECK_GE(10, length);
TrimRepresentation(buffer);
CHECK_EQ("35844466", buffer.start());
CHECK_EQ(299, point);
uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
double v = Double(smallest_normal64).value();
DoubleToAscii(v, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
uint32_t smallest_normal32 = 0x00800000;
float f = Single(smallest_normal32).value();
DoubleToAscii(f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("11754944", buffer.start());
CHECK_EQ(-37, point);
DoubleToAscii(v, PRECISION, 20, buffer, &sign, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("22250738585072013831", buffer.start());
CHECK_EQ(-307, point);
uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
v = Double(largest_denormal64).value();
DoubleToAscii(v, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point);
uint32_t largest_denormal32 = 0x007FFFFF;
f = Single(largest_denormal32).value();
DoubleToAscii(f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("11754942", buffer.start());
CHECK_EQ(-37, point);
DoubleToAscii(v, PRECISION, 20, buffer, &sign, &length, &point);
CHECK_GE(20, length);
TrimRepresentation(buffer);
CHECK_EQ("2225073858507200889", buffer.start());
CHECK_EQ(-307, point);
DoubleToAscii(4128420500802942e-24, SHORTEST, 0,
buffer, &sign, &length, &point);
CHECK_EQ(0, sign);
CHECK_EQ("4128420500802942", buffer.start());
CHECK_EQ(-8, point);
v = -3.9292015898194142585311918e-10;
DoubleToAscii(v, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK_EQ("39292015898194143", buffer.start());
f = -3.9292015898194142585311918e-10f;
DoubleToAscii(f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK_EQ("39292017", buffer.start());
v = 4194304.0;
DoubleToAscii(v, FIXED, 5, buffer, &sign, &length, &point);
CHECK_GE(5, length - point);
TrimRepresentation(buffer);
CHECK_EQ("4194304", buffer.start());
v = 3.3161339052167390562200598e-237;
DoubleToAscii(v, PRECISION, 19, buffer, &sign, &length, &point);
CHECK_GE(19, length);
TrimRepresentation(buffer);
CHECK_EQ("3316133905216739056", buffer.start());
CHECK_EQ(-236, point);
}
TEST(DtoaSign) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
DoubleToAscii(0.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-0.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(1.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-1.0, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(0.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-0.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(1.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-1.0f, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(0.0, PRECISION, 1, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-0.0, PRECISION, 1, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(1.0, PRECISION, 1, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-1.0, PRECISION, 1, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(0.0, FIXED, 1, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-0.0, FIXED, 1, buffer, &sign, &length, &point);
CHECK(sign);
DoubleToAscii(1.0, FIXED, 1, buffer, &sign, &length, &point);
CHECK(!sign);
DoubleToAscii(-1.0, FIXED, 1, buffer, &sign, &length, &point);
CHECK(sign);
}
TEST(DtoaCorners) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
DoubleToAscii(0.0, PRECISION, 0, buffer, &sign, &length, &point);
CHECK_EQ(0, length);
CHECK_EQ("", buffer.start());
CHECK(!sign);
DoubleToAscii(1.0, PRECISION, 0, buffer, &sign, &length, &point);
CHECK_EQ(0, length);
CHECK_EQ("", buffer.start());
CHECK(!sign);
DoubleToAscii(0.0, FIXED, 0, buffer, &sign, &length, &point);
CHECK_EQ(1, length);
CHECK_EQ("0", buffer.start());
CHECK(!sign);
DoubleToAscii(1.0, FIXED, 0, buffer, &sign, &length, &point);
CHECK_EQ(1, length);
CHECK_EQ("1", buffer.start());
CHECK(!sign);
}
TEST(DtoaGayShortest) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
Vector<const PrecomputedShortest> precomputed =
PrecomputedShortestRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortest current_test = precomputed[i];
double v = current_test.v;
DoubleToAscii(v, SHORTEST, 0, buffer, &sign, &length, &point);
CHECK(!sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(DtoaGayShortestSingle) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
Vector<const PrecomputedShortestSingle> precomputed =
PrecomputedShortestSingleRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortestSingle current_test = precomputed[i];
float v = current_test.v;
DoubleToAscii(v, SHORTEST_SINGLE, 0, buffer, &sign, &length, &point);
CHECK(!sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(DtoaGayFixed) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
Vector<const PrecomputedFixed> precomputed =
PrecomputedFixedRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedFixed current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
DoubleToAscii(v, FIXED, number_digits, buffer, &sign, &length, &point);
CHECK(!sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length - point);
TrimRepresentation(buffer);
CHECK_EQ(current_test.representation, buffer.start());
}
}
TEST(DtoaGayPrecision) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool sign;
int length;
int point;
Vector<const PrecomputedPrecision> precomputed =
PrecomputedPrecisionRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedPrecision current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
DoubleToAscii(v, PRECISION, number_digits,
buffer, &sign, &length, &point);
CHECK(!sign); // All precomputed numbers are positive.
CHECK_EQ(current_test.decimal_point, point);
CHECK_GE(number_digits, length);
TrimRepresentation(buffer);
CHECK_EQ(current_test.representation, buffer.start());
}
}

View File

@ -1,372 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
#include <stdlib.h>
#include "cctest.h"
#include "diy-fp.h"
#include "fast-dtoa.h"
#include "gay-precision.h"
#include "gay-shortest.h"
#include "gay-shortest-single.h"
#include "ieee.h"
#include "utils.h"
using namespace double_conversion;
static const int kBufferSize = 100;
// Removes trailing '0' digits.
static void TrimRepresentation(Vector<char> representation) {
int len = strlen(representation.start());
int i;
for (i = len - 1; i >= 0; --i) {
if (representation[i] != '0') break;
}
representation[i + 1] = '\0';
}
TEST(FastDtoaShortestVariousDoubles) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
bool status;
double min_double = 5e-324;
status = FastDtoa(min_double, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("5", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("17976931348623157", buffer.start());
CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(4.1855804968213567e298, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("4185580496821357", buffer.start());
CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("5562684646268003", buffer.start());
CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("2147483648", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_SHORTEST, 0,
buffer, &length, &point);
if (status) { // Not all FastDtoa variants manage to compute this number.
CHECK_EQ("35844466002796428", buffer.start());
CHECK_EQ(299, point);
}
uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
double v = Double(smallest_normal64).value();
status = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
if (status) {
CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
}
uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
v = Double(largest_denormal64).value();
status = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
if (status) {
CHECK_EQ("2225073858507201", buffer.start());
CHECK_EQ(-307, point);
}
}
TEST(FastDtoaShortestVariousFloats) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
bool status;
float min_float = 1e-45f;
status = FastDtoa(min_float, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("1", buffer.start());
CHECK_EQ(-44, point);
float max_float = 3.4028234e38f;
status = FastDtoa(max_float, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("34028235", buffer.start());
CHECK_EQ(39, point);
status = FastDtoa(4294967272.0f, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("42949673", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(3.32306998946228968226e+35f, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("332307", buffer.start());
CHECK_EQ(36, point);
status = FastDtoa(1.2341e-41f, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("12341", buffer.start());
CHECK_EQ(-40, point);
status = FastDtoa(3.3554432e7, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("33554432", buffer.start());
CHECK_EQ(8, point);
status = FastDtoa(3.26494756798464e14f, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("32649476", buffer.start());
CHECK_EQ(15, point);
status = FastDtoa(3.91132223637771935344e37f, FAST_DTOA_SHORTEST_SINGLE, 0,
buffer, &length, &point);
if (status) { // Not all FastDtoa variants manage to compute this number.
CHECK_EQ("39113222", buffer.start());
CHECK_EQ(38, point);
}
uint32_t smallest_normal32 = 0x00800000;
float v = Single(smallest_normal32).value();
status = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
if (status) {
CHECK_EQ("11754944", buffer.start());
CHECK_EQ(-37, point);
}
uint32_t largest_denormal32 = 0x007FFFFF;
v = Single(largest_denormal32).value();
status = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
CHECK(status);
CHECK_EQ("11754942", buffer.start());
CHECK_EQ(-37, point);
}
TEST(FastDtoaPrecisionVariousDoubles) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
bool status;
status = FastDtoa(1.0, FAST_DTOA_PRECISION, 3, buffer, &length, &point);
CHECK(status);
CHECK(3 >= length);
TrimRepresentation(buffer);
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
status = FastDtoa(1.5, FAST_DTOA_PRECISION, 10, buffer, &length, &point);
if (status) {
CHECK(10 >= length);
TrimRepresentation(buffer);
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
}
double min_double = 5e-324;
status = FastDtoa(min_double, FAST_DTOA_PRECISION, 5,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("49407", buffer.start());
CHECK_EQ(-323, point);
double max_double = 1.7976931348623157e308;
status = FastDtoa(max_double, FAST_DTOA_PRECISION, 7,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("1797693", buffer.start());
CHECK_EQ(309, point);
status = FastDtoa(4294967272.0, FAST_DTOA_PRECISION, 14,
buffer, &length, &point);
if (status) {
CHECK(14 >= length);
TrimRepresentation(buffer);
CHECK_EQ("4294967272", buffer.start());
CHECK_EQ(10, point);
}
status = FastDtoa(4.1855804968213567e298, FAST_DTOA_PRECISION, 17,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("41855804968213567", buffer.start());
CHECK_EQ(299, point);
status = FastDtoa(5.5626846462680035e-309, FAST_DTOA_PRECISION, 1,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("6", buffer.start());
CHECK_EQ(-308, point);
status = FastDtoa(2147483648.0, FAST_DTOA_PRECISION, 5,
buffer, &length, &point);
CHECK(status);
CHECK_EQ("21475", buffer.start());
CHECK_EQ(10, point);
status = FastDtoa(3.5844466002796428e+298, FAST_DTOA_PRECISION, 10,
buffer, &length, &point);
CHECK(status);
CHECK(10 >= length);
TrimRepresentation(buffer);
CHECK_EQ("35844466", buffer.start());
CHECK_EQ(299, point);
uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
double v = Double(smallest_normal64).value();
status = FastDtoa(v, FAST_DTOA_PRECISION, 17, buffer, &length, &point);
CHECK(status);
CHECK_EQ("22250738585072014", buffer.start());
CHECK_EQ(-307, point);
uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
v = Double(largest_denormal64).value();
status = FastDtoa(v, FAST_DTOA_PRECISION, 17, buffer, &length, &point);
CHECK(status);
CHECK(20 >= length);
TrimRepresentation(buffer);
CHECK_EQ("22250738585072009", buffer.start());
CHECK_EQ(-307, point);
v = 3.3161339052167390562200598e-237;
status = FastDtoa(v, FAST_DTOA_PRECISION, 18, buffer, &length, &point);
CHECK(status);
CHECK_EQ("331613390521673906", buffer.start());
CHECK_EQ(-236, point);
v = 7.9885183916008099497815232e+191;
status = FastDtoa(v, FAST_DTOA_PRECISION, 4, buffer, &length, &point);
CHECK(status);
CHECK_EQ("7989", buffer.start());
CHECK_EQ(192, point);
}
TEST(FastDtoaGayShortest) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int length;
int point;
int succeeded = 0;
int total = 0;
bool needed_max_length = false;
Vector<const PrecomputedShortest> precomputed =
PrecomputedShortestRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortest current_test = precomputed[i];
total++;
double v = current_test.v;
status = FastDtoa(v, FAST_DTOA_SHORTEST, 0, buffer, &length, &point);
CHECK(kFastDtoaMaximalLength >= length);
if (!status) continue;
if (length == kFastDtoaMaximalLength) needed_max_length = true;
succeeded++;
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
CHECK(succeeded*1.0/total > 0.99);
CHECK(needed_max_length);
}
TEST(FastDtoaGayShortestSingle) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int length;
int point;
int succeeded = 0;
int total = 0;
bool needed_max_length = false;
Vector<const PrecomputedShortestSingle> precomputed =
PrecomputedShortestSingleRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedShortestSingle current_test = precomputed[i];
total++;
float v = current_test.v;
status = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
CHECK(kFastDtoaMaximalSingleLength >= length);
if (!status) continue;
if (length == kFastDtoaMaximalSingleLength) needed_max_length = true;
succeeded++;
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
CHECK(succeeded*1.0/total > 0.98);
CHECK(needed_max_length);
}
TEST(FastDtoaGayPrecision) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int length;
int point;
int succeeded = 0;
int total = 0;
// Count separately for entries with less than 15 requested digits.
int succeeded_15 = 0;
int total_15 = 0;
Vector<const PrecomputedPrecision> precomputed =
PrecomputedPrecisionRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedPrecision current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
total++;
if (number_digits <= 15) total_15++;
status = FastDtoa(v, FAST_DTOA_PRECISION, number_digits,
buffer, &length, &point);
CHECK(number_digits >= length);
if (!status) continue;
succeeded++;
if (number_digits <= 15) succeeded_15++;
TrimRepresentation(buffer);
CHECK_EQ(current_test.decimal_point, point);
CHECK_EQ(current_test.representation, buffer.start());
}
// The precomputed numbers contain many entries with many requested
// digits. These have a high failure rate and we therefore expect a lower
// success rate than for the shortest representation.
CHECK(succeeded*1.0/total > 0.85);
// However with less than 15 digits almost the algorithm should almost always
// succeed.
CHECK(succeeded_15*1.0/total_15 > 0.9999);
}

View File

@ -1,511 +0,0 @@
// Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include "cctest.h"
#include "fixed-dtoa.h"
#include "gay-fixed.h"
#include "ieee.h"
#include "utils.h"
using namespace double_conversion;
static const int kBufferSize = 500;
TEST(FastFixedVariousDoubles) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
int length;
int point;
CHECK(FastFixedDtoa(1.0, 1, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1.0, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1.0, 0, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0xFFFFFFFF, 5, buffer, &length, &point));
CHECK_EQ("4294967295", buffer.start());
CHECK_EQ(10, point);
CHECK(FastFixedDtoa(4294967296.0, 5, buffer, &length, &point));
CHECK_EQ("4294967296", buffer.start());
CHECK_EQ(10, point);
CHECK(FastFixedDtoa(1e21, 5, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
// CHECK_EQ(22, point);
CHECK_EQ(22, point);
CHECK(FastFixedDtoa(999999999999999868928.00, 2, buffer, &length, &point));
CHECK_EQ("999999999999999868928", buffer.start());
CHECK_EQ(21, point);
CHECK(FastFixedDtoa(6.9999999999999989514240000e+21, 5, buffer,
&length, &point));
CHECK_EQ("6999999999999998951424", buffer.start());
CHECK_EQ(22, point);
CHECK(FastFixedDtoa(1.5, 5, buffer, &length, &point));
CHECK_EQ("15", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1.55, 5, buffer, &length, &point));
CHECK_EQ("155", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1.55, 1, buffer, &length, &point));
CHECK_EQ("16", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1.00000001, 15, buffer, &length, &point));
CHECK_EQ("100000001", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.1, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(0, point);
CHECK(FastFixedDtoa(0.01, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-1, point);
CHECK(FastFixedDtoa(0.001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-2, point);
CHECK(FastFixedDtoa(0.0001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(0.00001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-4, point);
CHECK(FastFixedDtoa(0.000001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-5, point);
CHECK(FastFixedDtoa(0.0000001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-6, point);
CHECK(FastFixedDtoa(0.00000001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-7, point);
CHECK(FastFixedDtoa(0.000000001, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-8, point);
CHECK(FastFixedDtoa(0.0000000001, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-9, point);
CHECK(FastFixedDtoa(0.00000000001, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-10, point);
CHECK(FastFixedDtoa(0.000000000001, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-11, point);
CHECK(FastFixedDtoa(0.0000000000001, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-12, point);
CHECK(FastFixedDtoa(0.00000000000001, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-13, point);
CHECK(FastFixedDtoa(0.000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-14, point);
CHECK(FastFixedDtoa(0.0000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-15, point);
CHECK(FastFixedDtoa(0.00000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-16, point);
CHECK(FastFixedDtoa(0.000000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-17, point);
CHECK(FastFixedDtoa(0.0000000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-18, point);
CHECK(FastFixedDtoa(0.00000000000000000001, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-19, point);
CHECK(FastFixedDtoa(0.10000000004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(0, point);
CHECK(FastFixedDtoa(0.01000000004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-1, point);
CHECK(FastFixedDtoa(0.00100000004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-2, point);
CHECK(FastFixedDtoa(0.00010000004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(0.00001000004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-4, point);
CHECK(FastFixedDtoa(0.00000100004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-5, point);
CHECK(FastFixedDtoa(0.00000010004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-6, point);
CHECK(FastFixedDtoa(0.00000001004, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-7, point);
CHECK(FastFixedDtoa(0.00000000104, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-8, point);
CHECK(FastFixedDtoa(0.0000000001000004, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-9, point);
CHECK(FastFixedDtoa(0.0000000000100004, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-10, point);
CHECK(FastFixedDtoa(0.0000000000010004, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-11, point);
CHECK(FastFixedDtoa(0.0000000000001004, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-12, point);
CHECK(FastFixedDtoa(0.0000000000000104, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-13, point);
CHECK(FastFixedDtoa(0.000000000000001000004, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-14, point);
CHECK(FastFixedDtoa(0.000000000000000100004, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-15, point);
CHECK(FastFixedDtoa(0.000000000000000010004, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-16, point);
CHECK(FastFixedDtoa(0.000000000000000001004, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-17, point);
CHECK(FastFixedDtoa(0.000000000000000000104, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-18, point);
CHECK(FastFixedDtoa(0.000000000000000000014, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-19, point);
CHECK(FastFixedDtoa(0.10000000006, 10, buffer, &length, &point));
CHECK_EQ("1000000001", buffer.start());
CHECK_EQ(0, point);
CHECK(FastFixedDtoa(0.01000000006, 10, buffer, &length, &point));
CHECK_EQ("100000001", buffer.start());
CHECK_EQ(-1, point);
CHECK(FastFixedDtoa(0.00100000006, 10, buffer, &length, &point));
CHECK_EQ("10000001", buffer.start());
CHECK_EQ(-2, point);
CHECK(FastFixedDtoa(0.00010000006, 10, buffer, &length, &point));
CHECK_EQ("1000001", buffer.start());
CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(0.00001000006, 10, buffer, &length, &point));
CHECK_EQ("100001", buffer.start());
CHECK_EQ(-4, point);
CHECK(FastFixedDtoa(0.00000100006, 10, buffer, &length, &point));
CHECK_EQ("10001", buffer.start());
CHECK_EQ(-5, point);
CHECK(FastFixedDtoa(0.00000010006, 10, buffer, &length, &point));
CHECK_EQ("1001", buffer.start());
CHECK_EQ(-6, point);
CHECK(FastFixedDtoa(0.00000001006, 10, buffer, &length, &point));
CHECK_EQ("101", buffer.start());
CHECK_EQ(-7, point);
CHECK(FastFixedDtoa(0.00000000106, 10, buffer, &length, &point));
CHECK_EQ("11", buffer.start());
CHECK_EQ(-8, point);
CHECK(FastFixedDtoa(0.0000000001000006, 15, buffer, &length, &point));
CHECK_EQ("100001", buffer.start());
CHECK_EQ(-9, point);
CHECK(FastFixedDtoa(0.0000000000100006, 15, buffer, &length, &point));
CHECK_EQ("10001", buffer.start());
CHECK_EQ(-10, point);
CHECK(FastFixedDtoa(0.0000000000010006, 15, buffer, &length, &point));
CHECK_EQ("1001", buffer.start());
CHECK_EQ(-11, point);
CHECK(FastFixedDtoa(0.0000000000001006, 15, buffer, &length, &point));
CHECK_EQ("101", buffer.start());
CHECK_EQ(-12, point);
CHECK(FastFixedDtoa(0.0000000000000106, 15, buffer, &length, &point));
CHECK_EQ("11", buffer.start());
CHECK_EQ(-13, point);
CHECK(FastFixedDtoa(0.000000000000001000006, 20, buffer, &length, &point));
CHECK_EQ("100001", buffer.start());
CHECK_EQ(-14, point);
CHECK(FastFixedDtoa(0.000000000000000100006, 20, buffer, &length, &point));
CHECK_EQ("10001", buffer.start());
CHECK_EQ(-15, point);
CHECK(FastFixedDtoa(0.000000000000000010006, 20, buffer, &length, &point));
CHECK_EQ("1001", buffer.start());
CHECK_EQ(-16, point);
CHECK(FastFixedDtoa(0.000000000000000001006, 20, buffer, &length, &point));
CHECK_EQ("101", buffer.start());
CHECK_EQ(-17, point);
CHECK(FastFixedDtoa(0.000000000000000000106, 20, buffer, &length, &point));
CHECK_EQ("11", buffer.start());
CHECK_EQ(-18, point);
CHECK(FastFixedDtoa(0.000000000000000000016, 20, buffer, &length, &point));
CHECK_EQ("2", buffer.start());
CHECK_EQ(-19, point);
CHECK(FastFixedDtoa(0.6, 0, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.96, 1, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.996, 2, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.9996, 3, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.99996, 4, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.999996, 5, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.9999996, 6, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.99999996, 7, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.999999996, 8, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.9999999996, 9, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.99999999996, 10, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.999999999996, 11, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.9999999999996, 12, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.99999999999996, 13, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.999999999999996, 14, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.9999999999999996, 15, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(0.00999999999999996, 16, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-1, point);
CHECK(FastFixedDtoa(0.000999999999999996, 17, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-2, point);
CHECK(FastFixedDtoa(0.0000999999999999996, 18, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(0.00000999999999999996, 19, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-4, point);
CHECK(FastFixedDtoa(0.000000999999999999996, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-5, point);
CHECK(FastFixedDtoa(323423.234234, 10, buffer, &length, &point));
CHECK_EQ("323423234234", buffer.start());
CHECK_EQ(6, point);
CHECK(FastFixedDtoa(12345678.901234, 4, buffer, &length, &point));
CHECK_EQ("123456789012", buffer.start());
CHECK_EQ(8, point);
CHECK(FastFixedDtoa(98765.432109, 5, buffer, &length, &point));
CHECK_EQ("9876543211", buffer.start());
CHECK_EQ(5, point);
CHECK(FastFixedDtoa(42, 20, buffer, &length, &point));
CHECK_EQ("42", buffer.start());
CHECK_EQ(2, point);
CHECK(FastFixedDtoa(0.5, 0, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(1, point);
CHECK(FastFixedDtoa(1e-23, 10, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-10, point);
CHECK(FastFixedDtoa(1e-123, 2, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-2, point);
CHECK(FastFixedDtoa(1e-123, 0, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(0, point);
CHECK(FastFixedDtoa(1e-23, 20, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-20, point);
CHECK(FastFixedDtoa(1e-21, 20, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-20, point);
CHECK(FastFixedDtoa(1e-22, 20, buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-20, point);
CHECK(FastFixedDtoa(6e-21, 20, buffer, &length, &point));
CHECK_EQ("1", buffer.start());
CHECK_EQ(-19, point);
CHECK(FastFixedDtoa(9.1193616301674545152000000e+19, 0,
buffer, &length, &point));
CHECK_EQ("91193616301674545152", buffer.start());
CHECK_EQ(20, point);
CHECK(FastFixedDtoa(4.8184662102767651659096515e-04, 19,
buffer, &length, &point));
CHECK_EQ("4818466210276765", buffer.start());
CHECK_EQ(-3, point);
CHECK(FastFixedDtoa(1.9023164229540652612705182e-23, 8,
buffer, &length, &point));
CHECK_EQ("", buffer.start());
CHECK_EQ(-8, point);
CHECK(FastFixedDtoa(1000000000000000128.0, 0,
buffer, &length, &point));
CHECK_EQ("1000000000000000128", buffer.start());
CHECK_EQ(19, point);
}
TEST(FastFixedDtoaGayFixed) {
char buffer_container[kBufferSize];
Vector<char> buffer(buffer_container, kBufferSize);
bool status;
int length;
int point;
Vector<const PrecomputedFixed> precomputed =
PrecomputedFixedRepresentations();
for (int i = 0; i < precomputed.length(); ++i) {
const PrecomputedFixed current_test = precomputed[i];
double v = current_test.v;
int number_digits = current_test.number_digits;
status = FastFixedDtoa(v, number_digits,
buffer, &length, &point);
CHECK(status);
CHECK_EQ(current_test.decimal_point, point);
CHECK(number_digits >= length - point);
CHECK_EQ(current_test.representation, buffer.start());
}
}

View File

@ -1,422 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
#include <stdlib.h>
#include "cctest.h"
#include "diy-fp.h"
#include "ieee.h"
#include "utils.h"
#include "../../src/ieee.h"
using namespace double_conversion;
TEST(Uint64Conversions) {
// Start by checking the byte-order.
uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
CHECK_EQ(3512700564088504e-318, Double(ordered).value());
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
CHECK_EQ(5e-324, Double(min_double64).value());
uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
CHECK_EQ(1.7976931348623157e308, Double(max_double64).value());
}
TEST(Uint32Conversions) {
// Start by checking the byte-order.
uint32_t ordered = 0x01234567;
CHECK_EQ(2.9988165487136453e-38f, Single(ordered).value());
uint32_t min_float32 = 0x00000001;
CHECK_EQ(1.4e-45f, Single(min_float32).value());
uint32_t max_float32 = 0x7f7fffff;
CHECK_EQ(3.4028234e38f, Single(max_float32).value());
}
TEST(Double_AsDiyFp) {
uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
DiyFp diy_fp = Double(ordered).AsDiyFp();
CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e());
// The 52 mantissa bits, plus the implicit 1 in bit 52 as a UINT64.
CHECK(UINT64_2PART_C(0x00134567, 89ABCDEF) == diy_fp.f()); // NOLINT
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
diy_fp = Double(min_double64).AsDiyFp();
CHECK_EQ(-0x3FF - 52 + 1, diy_fp.e());
// This is a denormal; so no hidden bit.
CHECK(1 == diy_fp.f()); // NOLINT
uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
diy_fp = Double(max_double64).AsDiyFp();
CHECK_EQ(0x7FE - 0x3FF - 52, diy_fp.e());
CHECK(UINT64_2PART_C(0x001fffff, ffffffff) == diy_fp.f()); // NOLINT
}
TEST(Single_AsDiyFp) {
uint32_t ordered = 0x01234567;
DiyFp diy_fp = Single(ordered).AsDiyFp();
CHECK_EQ(0x2 - 0x7F - 23, diy_fp.e());
// The 23 mantissa bits, plus the implicit 1 in bit 24 as a uint32_t.
CHECK_EQ(0xA34567, diy_fp.f());
uint32_t min_float32 = 0x00000001;
diy_fp = Single(min_float32).AsDiyFp();
CHECK_EQ(-0x7F - 23 + 1, diy_fp.e());
// This is a denormal; so no hidden bit.
CHECK_EQ(1, diy_fp.f());
uint32_t max_float32 = 0x7f7fffff;
diy_fp = Single(max_float32).AsDiyFp();
CHECK_EQ(0xFE - 0x7F - 23, diy_fp.e());
CHECK_EQ(0x00ffffff, diy_fp.f());
}
TEST(AsNormalizedDiyFp) {
uint64_t ordered = UINT64_2PART_C(0x01234567, 89ABCDEF);
DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp();
CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e());
CHECK((UINT64_2PART_C(0x00134567, 89ABCDEF) << 11) ==
diy_fp.f()); // NOLINT
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
diy_fp = Double(min_double64).AsNormalizedDiyFp();
CHECK_EQ(-0x3FF - 52 + 1 - 63, diy_fp.e());
// This is a denormal; so no hidden bit.
CHECK(UINT64_2PART_C(0x80000000, 00000000) == diy_fp.f()); // NOLINT
uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
diy_fp = Double(max_double64).AsNormalizedDiyFp();
CHECK_EQ(0x7FE - 0x3FF - 52 - 11, diy_fp.e());
CHECK((UINT64_2PART_C(0x001fffff, ffffffff) << 11) ==
diy_fp.f()); // NOLINT
}
TEST(Double_IsDenormal) {
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
CHECK(Double(min_double64).IsDenormal());
uint64_t bits = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
CHECK(Double(bits).IsDenormal());
bits = UINT64_2PART_C(0x00100000, 00000000);
CHECK(!Double(bits).IsDenormal());
}
TEST(Single_IsDenormal) {
uint32_t min_float32 = 0x00000001;
CHECK(Single(min_float32).IsDenormal());
uint32_t bits = 0x007FFFFF;
CHECK(Single(bits).IsDenormal());
bits = 0x00800000;
CHECK(!Single(bits).IsDenormal());
}
TEST(Double_IsSpecial) {
CHECK(Double(Double::Infinity()).IsSpecial());
CHECK(Double(-Double::Infinity()).IsSpecial());
CHECK(Double(Double::NaN()).IsSpecial());
uint64_t bits = UINT64_2PART_C(0xFFF12345, 00000000);
CHECK(Double(bits).IsSpecial());
// Denormals are not special:
CHECK(!Double(5e-324).IsSpecial());
CHECK(!Double(-5e-324).IsSpecial());
// And some random numbers:
CHECK(!Double(0.0).IsSpecial());
CHECK(!Double(-0.0).IsSpecial());
CHECK(!Double(1.0).IsSpecial());
CHECK(!Double(-1.0).IsSpecial());
CHECK(!Double(1000000.0).IsSpecial());
CHECK(!Double(-1000000.0).IsSpecial());
CHECK(!Double(1e23).IsSpecial());
CHECK(!Double(-1e23).IsSpecial());
CHECK(!Double(1.7976931348623157e308).IsSpecial());
CHECK(!Double(-1.7976931348623157e308).IsSpecial());
}
TEST(Single_IsSpecial) {
CHECK(Single(Single::Infinity()).IsSpecial());
CHECK(Single(-Single::Infinity()).IsSpecial());
CHECK(Single(Single::NaN()).IsSpecial());
uint32_t bits = 0xFFF12345;
CHECK(Single(bits).IsSpecial());
// Denormals are not special:
CHECK(!Single(1.4e-45f).IsSpecial());
CHECK(!Single(-1.4e-45f).IsSpecial());
// And some random numbers:
CHECK(!Single(0.0f).IsSpecial());
CHECK(!Single(-0.0f).IsSpecial());
CHECK(!Single(1.0f).IsSpecial());
CHECK(!Single(-1.0f).IsSpecial());
CHECK(!Single(1000000.0f).IsSpecial());
CHECK(!Single(-1000000.0f).IsSpecial());
CHECK(!Single(1e23f).IsSpecial());
CHECK(!Single(-1e23f).IsSpecial());
CHECK(!Single(1.18e-38f).IsSpecial());
CHECK(!Single(-1.18e-38f).IsSpecial());
}
TEST(Double_IsInfinite) {
CHECK(Double(Double::Infinity()).IsInfinite());
CHECK(Double(-Double::Infinity()).IsInfinite());
CHECK(!Double(Double::NaN()).IsInfinite());
CHECK(!Double(0.0).IsInfinite());
CHECK(!Double(-0.0).IsInfinite());
CHECK(!Double(1.0).IsInfinite());
CHECK(!Double(-1.0).IsInfinite());
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
CHECK(!Double(min_double64).IsInfinite());
}
TEST(Single_IsInfinite) {
CHECK(Single(Single::Infinity()).IsInfinite());
CHECK(Single(-Single::Infinity()).IsInfinite());
CHECK(!Single(Single::NaN()).IsInfinite());
CHECK(!Single(0.0f).IsInfinite());
CHECK(!Single(-0.0f).IsInfinite());
CHECK(!Single(1.0f).IsInfinite());
CHECK(!Single(-1.0f).IsInfinite());
uint32_t min_float32 = 0x00000001;
CHECK(!Single(min_float32).IsInfinite());
}
TEST(Double_IsNan) {
CHECK(Double(Double::NaN()).IsNan());
uint64_t other_nan = UINT64_2PART_C(0xFFFFFFFF, 00000001);
CHECK(Double(other_nan).IsNan());
CHECK(!Double(Double::Infinity()).IsNan());
CHECK(!Double(-Double::Infinity()).IsNan());
CHECK(!Double(0.0).IsNan());
CHECK(!Double(-0.0).IsNan());
CHECK(!Double(1.0).IsNan());
CHECK(!Double(-1.0).IsNan());
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
CHECK(!Double(min_double64).IsNan());
}
TEST(Single_IsNan) {
CHECK(Single(Single::NaN()).IsNan());
uint32_t other_nan = 0xFFFFF001;
CHECK(Single(other_nan).IsNan());
CHECK(!Single(Single::Infinity()).IsNan());
CHECK(!Single(-Single::Infinity()).IsNan());
CHECK(!Single(0.0f).IsNan());
CHECK(!Single(-0.0f).IsNan());
CHECK(!Single(1.0f).IsNan());
CHECK(!Single(-1.0f).IsNan());
uint32_t min_float32 = 0x00000001;
CHECK(!Single(min_float32).IsNan());
}
TEST(Double_Sign) {
CHECK_EQ(1, Double(1.0).Sign());
CHECK_EQ(1, Double(Double::Infinity()).Sign());
CHECK_EQ(-1, Double(-Double::Infinity()).Sign());
CHECK_EQ(1, Double(0.0).Sign());
CHECK_EQ(-1, Double(-0.0).Sign());
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
CHECK_EQ(1, Double(min_double64).Sign());
}
TEST(Single_Sign) {
CHECK_EQ(1, Single(1.0f).Sign());
CHECK_EQ(1, Single(Single::Infinity()).Sign());
CHECK_EQ(-1, Single(-Single::Infinity()).Sign());
CHECK_EQ(1, Single(0.0f).Sign());
CHECK_EQ(-1, Single(-0.0f).Sign());
uint32_t min_float32 = 0x00000001;
CHECK_EQ(1, Single(min_float32).Sign());
}
TEST(Double_NormalizedBoundaries) {
DiyFp boundary_plus;
DiyFp boundary_minus;
DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp();
Double(1.5).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// 1.5 does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
diy_fp = Double(1.0).AsNormalizedDiyFp();
Double(1.0).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// 1.0 does have a significand of the form 2^p (for some p).
// Therefore its lower boundary is twice as close as the upper boundary.
CHECK(boundary_plus.f() - diy_fp.f() > diy_fp.f() - boundary_minus.f());
CHECK((1 << 9) == diy_fp.f() - boundary_minus.f()); // NOLINT
CHECK((1 << 10) == boundary_plus.f() - diy_fp.f()); // NOLINT
uint64_t min_double64 = UINT64_2PART_C(0x00000000, 00000001);
diy_fp = Double(min_double64).AsNormalizedDiyFp();
Double(min_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// min-value does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
// Denormals have their boundaries much closer.
CHECK((static_cast<uint64_t>(1) << 62) ==
diy_fp.f() - boundary_minus.f()); // NOLINT
uint64_t smallest_normal64 = UINT64_2PART_C(0x00100000, 00000000);
diy_fp = Double(smallest_normal64).AsNormalizedDiyFp();
Double(smallest_normal64).NormalizedBoundaries(&boundary_minus,
&boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// Even though the significand is of the form 2^p (for some p), its boundaries
// are at the same distance. (This is the only exception).
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
uint64_t largest_denormal64 = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
diy_fp = Double(largest_denormal64).AsNormalizedDiyFp();
Double(largest_denormal64).NormalizedBoundaries(&boundary_minus,
&boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((1 << 11) == diy_fp.f() - boundary_minus.f()); // NOLINT
uint64_t max_double64 = UINT64_2PART_C(0x7fefffff, ffffffff);
diy_fp = Double(max_double64).AsNormalizedDiyFp();
Double(max_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// max-value does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT
}
TEST(Single_NormalizedBoundaries) {
uint64_t kOne64 = 1;
DiyFp boundary_plus;
DiyFp boundary_minus;
DiyFp diy_fp = Single(1.5f).AsDiyFp();
diy_fp.Normalize();
Single(1.5f).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// 1.5 does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
// Normalization shifts the significand by 8 bits. Add 32 bits for the bigger
// data-type, and remove 1 because boundaries are at half a ULP.
CHECK((kOne64 << 39) == diy_fp.f() - boundary_minus.f());
diy_fp = Single(1.0f).AsDiyFp();
diy_fp.Normalize();
Single(1.0f).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// 1.0 does have a significand of the form 2^p (for some p).
// Therefore its lower boundary is twice as close as the upper boundary.
CHECK(boundary_plus.f() - diy_fp.f() > diy_fp.f() - boundary_minus.f());
CHECK((kOne64 << 38) == diy_fp.f() - boundary_minus.f()); // NOLINT
CHECK((kOne64 << 39) == boundary_plus.f() - diy_fp.f()); // NOLINT
uint32_t min_float32 = 0x00000001;
diy_fp = Single(min_float32).AsDiyFp();
diy_fp.Normalize();
Single(min_float32).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// min-value does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
// Denormals have their boundaries much closer.
CHECK((kOne64 << 62) == diy_fp.f() - boundary_minus.f()); // NOLINT
uint32_t smallest_normal32 = 0x00800000;
diy_fp = Single(smallest_normal32).AsDiyFp();
diy_fp.Normalize();
Single(smallest_normal32).NormalizedBoundaries(&boundary_minus,
&boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// Even though the significand is of the form 2^p (for some p), its boundaries
// are at the same distance. (This is the only exception).
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((kOne64 << 39) == diy_fp.f() - boundary_minus.f()); // NOLINT
uint32_t largest_denormal32 = 0x007FFFFF;
diy_fp = Single(largest_denormal32).AsDiyFp();
diy_fp.Normalize();
Single(largest_denormal32).NormalizedBoundaries(&boundary_minus,
&boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((kOne64 << 40) == diy_fp.f() - boundary_minus.f()); // NOLINT
uint32_t max_float32 = 0x7f7fffff;
diy_fp = Single(max_float32).AsDiyFp();
diy_fp.Normalize();
Single(max_float32).NormalizedBoundaries(&boundary_minus, &boundary_plus);
CHECK_EQ(diy_fp.e(), boundary_minus.e());
CHECK_EQ(diy_fp.e(), boundary_plus.e());
// max-value does not have a significand of the form 2^p (for some p).
// Therefore its boundaries are at the same distance.
CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f());
CHECK((kOne64 << 39) == diy_fp.f() - boundary_minus.f()); // NOLINT
}
TEST(NextDouble) {
CHECK_EQ(4e-324, Double(0.0).NextDouble());
CHECK_EQ(0.0, Double(-0.0).NextDouble());
CHECK_EQ(-0.0, Double(-4e-324).NextDouble());
CHECK(Double(Double(-0.0).NextDouble()).Sign() > 0);
CHECK(Double(Double(-4e-324).NextDouble()).Sign() < 0);
Double d0(-4e-324);
Double d1(d0.NextDouble());
Double d2(d1.NextDouble());
CHECK_EQ(-0.0, d1.value());
CHECK(d1.Sign() < 0);
CHECK_EQ(0.0, d2.value());
CHECK(d2.Sign() > 0);
CHECK_EQ(4e-324, d2.NextDouble());
CHECK_EQ(-1.7976931348623157e308, Double(-Double::Infinity()).NextDouble());
CHECK_EQ(Double::Infinity(),
Double(UINT64_2PART_C(0x7fefffff, ffffffff)).NextDouble());
}
TEST(PreviousDouble) {
CHECK_EQ(0.0, Double(4e-324).PreviousDouble());
CHECK_EQ(-0.0, Double(0.0).PreviousDouble());
CHECK(Double(Double(0.0).PreviousDouble()).Sign() < 0);
CHECK_EQ(-4e-324, Double(-0.0).PreviousDouble());
Double d0(4e-324);
Double d1(d0.PreviousDouble());
Double d2(d1.PreviousDouble());
CHECK_EQ(0.0, d1.value());
CHECK(d1.Sign() > 0);
CHECK_EQ(-0.0, d2.value());
CHECK(d2.Sign() < 0);
CHECK_EQ(-4e-324, d2.PreviousDouble());
CHECK_EQ(1.7976931348623157e308, Double(Double::Infinity()).PreviousDouble());
CHECK_EQ(-Double::Infinity(),
Double(UINT64_2PART_C(0xffefffff, ffffffff)).PreviousDouble());
}

View File

@ -1,751 +0,0 @@
// Copyright 2006-2008 the V8 project authors. All rights reserved.
#include <stdlib.h>
#include "bignum.h"
#include "cctest.h"
#include "diy-fp.h"
#include "ieee.h"
#include "strtod.h"
#include "utils.h"
using namespace double_conversion;
static Vector<const char> StringToVector(const char* str) {
return Vector<const char>(str, strlen(str));
}
static double StrtodChar(const char* str, int exponent) {
return Strtod(StringToVector(str), exponent);
}
static float StrtofChar(const char* str, int exponent) {
return Strtof(StringToVector(str), exponent);
}
TEST(Strtod) {
Vector<const char> vector;
vector = StringToVector("0");
CHECK_EQ(0.0, Strtod(vector, 1));
CHECK_EQ(0.0, Strtod(vector, 2));
CHECK_EQ(0.0, Strtod(vector, -2));
CHECK_EQ(0.0, Strtod(vector, -999));
CHECK_EQ(0.0, Strtod(vector, +999));
vector = StringToVector("1");
CHECK_EQ(1.0, Strtod(vector, 0));
CHECK_EQ(10.0, Strtod(vector, 1));
CHECK_EQ(100.0, Strtod(vector, 2));
CHECK_EQ(1e20, Strtod(vector, 20));
CHECK_EQ(1e22, Strtod(vector, 22));
CHECK_EQ(1e23, Strtod(vector, 23));
CHECK_EQ(1e35, Strtod(vector, 35));
CHECK_EQ(1e36, Strtod(vector, 36));
CHECK_EQ(1e37, Strtod(vector, 37));
CHECK_EQ(1e-1, Strtod(vector, -1));
CHECK_EQ(1e-2, Strtod(vector, -2));
CHECK_EQ(1e-5, Strtod(vector, -5));
CHECK_EQ(1e-20, Strtod(vector, -20));
CHECK_EQ(1e-22, Strtod(vector, -22));
CHECK_EQ(1e-23, Strtod(vector, -23));
CHECK_EQ(1e-25, Strtod(vector, -25));
CHECK_EQ(1e-39, Strtod(vector, -39));
vector = StringToVector("2");
CHECK_EQ(2.0, Strtod(vector, 0));
CHECK_EQ(20.0, Strtod(vector, 1));
CHECK_EQ(200.0, Strtod(vector, 2));
CHECK_EQ(2e20, Strtod(vector, 20));
CHECK_EQ(2e22, Strtod(vector, 22));
CHECK_EQ(2e23, Strtod(vector, 23));
CHECK_EQ(2e35, Strtod(vector, 35));
CHECK_EQ(2e36, Strtod(vector, 36));
CHECK_EQ(2e37, Strtod(vector, 37));
CHECK_EQ(2e-1, Strtod(vector, -1));
CHECK_EQ(2e-2, Strtod(vector, -2));
CHECK_EQ(2e-5, Strtod(vector, -5));
CHECK_EQ(2e-20, Strtod(vector, -20));
CHECK_EQ(2e-22, Strtod(vector, -22));
CHECK_EQ(2e-23, Strtod(vector, -23));
CHECK_EQ(2e-25, Strtod(vector, -25));
CHECK_EQ(2e-39, Strtod(vector, -39));
vector = StringToVector("9");
CHECK_EQ(9.0, Strtod(vector, 0));
CHECK_EQ(90.0, Strtod(vector, 1));
CHECK_EQ(900.0, Strtod(vector, 2));
CHECK_EQ(9e20, Strtod(vector, 20));
CHECK_EQ(9e22, Strtod(vector, 22));
CHECK_EQ(9e23, Strtod(vector, 23));
CHECK_EQ(9e35, Strtod(vector, 35));
CHECK_EQ(9e36, Strtod(vector, 36));
CHECK_EQ(9e37, Strtod(vector, 37));
CHECK_EQ(9e-1, Strtod(vector, -1));
CHECK_EQ(9e-2, Strtod(vector, -2));
CHECK_EQ(9e-5, Strtod(vector, -5));
CHECK_EQ(9e-20, Strtod(vector, -20));
CHECK_EQ(9e-22, Strtod(vector, -22));
CHECK_EQ(9e-23, Strtod(vector, -23));
CHECK_EQ(9e-25, Strtod(vector, -25));
CHECK_EQ(9e-39, Strtod(vector, -39));
vector = StringToVector("12345");
CHECK_EQ(12345.0, Strtod(vector, 0));
CHECK_EQ(123450.0, Strtod(vector, 1));
CHECK_EQ(1234500.0, Strtod(vector, 2));
CHECK_EQ(12345e20, Strtod(vector, 20));
CHECK_EQ(12345e22, Strtod(vector, 22));
CHECK_EQ(12345e23, Strtod(vector, 23));
CHECK_EQ(12345e30, Strtod(vector, 30));
CHECK_EQ(12345e31, Strtod(vector, 31));
CHECK_EQ(12345e32, Strtod(vector, 32));
CHECK_EQ(12345e35, Strtod(vector, 35));
CHECK_EQ(12345e36, Strtod(vector, 36));
CHECK_EQ(12345e37, Strtod(vector, 37));
CHECK_EQ(12345e-1, Strtod(vector, -1));
CHECK_EQ(12345e-2, Strtod(vector, -2));
CHECK_EQ(12345e-5, Strtod(vector, -5));
CHECK_EQ(12345e-20, Strtod(vector, -20));
CHECK_EQ(12345e-22, Strtod(vector, -22));
CHECK_EQ(12345e-23, Strtod(vector, -23));
CHECK_EQ(12345e-25, Strtod(vector, -25));
CHECK_EQ(12345e-39, Strtod(vector, -39));
vector = StringToVector("12345678901234");
CHECK_EQ(12345678901234.0, Strtod(vector, 0));
CHECK_EQ(123456789012340.0, Strtod(vector, 1));
CHECK_EQ(1234567890123400.0, Strtod(vector, 2));
CHECK_EQ(12345678901234e20, Strtod(vector, 20));
CHECK_EQ(12345678901234e22, Strtod(vector, 22));
CHECK_EQ(12345678901234e23, Strtod(vector, 23));
CHECK_EQ(12345678901234e30, Strtod(vector, 30));
CHECK_EQ(12345678901234e31, Strtod(vector, 31));
CHECK_EQ(12345678901234e32, Strtod(vector, 32));
CHECK_EQ(12345678901234e35, Strtod(vector, 35));
CHECK_EQ(12345678901234e36, Strtod(vector, 36));
CHECK_EQ(12345678901234e37, Strtod(vector, 37));
CHECK_EQ(12345678901234e-1, Strtod(vector, -1));
CHECK_EQ(12345678901234e-2, Strtod(vector, -2));
CHECK_EQ(12345678901234e-5, Strtod(vector, -5));
CHECK_EQ(12345678901234e-20, Strtod(vector, -20));
CHECK_EQ(12345678901234e-22, Strtod(vector, -22));
CHECK_EQ(12345678901234e-23, Strtod(vector, -23));
CHECK_EQ(12345678901234e-25, Strtod(vector, -25));
CHECK_EQ(12345678901234e-39, Strtod(vector, -39));
vector = StringToVector("123456789012345");
CHECK_EQ(123456789012345.0, Strtod(vector, 0));
CHECK_EQ(1234567890123450.0, Strtod(vector, 1));
CHECK_EQ(12345678901234500.0, Strtod(vector, 2));
CHECK_EQ(123456789012345e20, Strtod(vector, 20));
CHECK_EQ(123456789012345e22, Strtod(vector, 22));
CHECK_EQ(123456789012345e23, Strtod(vector, 23));
CHECK_EQ(123456789012345e35, Strtod(vector, 35));
CHECK_EQ(123456789012345e36, Strtod(vector, 36));
CHECK_EQ(123456789012345e37, Strtod(vector, 37));
CHECK_EQ(123456789012345e39, Strtod(vector, 39));
CHECK_EQ(123456789012345e-1, Strtod(vector, -1));
CHECK_EQ(123456789012345e-2, Strtod(vector, -2));
CHECK_EQ(123456789012345e-5, Strtod(vector, -5));
CHECK_EQ(123456789012345e-20, Strtod(vector, -20));
CHECK_EQ(123456789012345e-22, Strtod(vector, -22));
CHECK_EQ(123456789012345e-23, Strtod(vector, -23));
CHECK_EQ(123456789012345e-25, Strtod(vector, -25));
CHECK_EQ(123456789012345e-39, Strtod(vector, -39));
CHECK_EQ(0.0, StrtodChar("0", 12345));
CHECK_EQ(0.0, StrtodChar("", 1324));
CHECK_EQ(0.0, StrtodChar("000000000", 123));
CHECK_EQ(0.0, StrtodChar("2", -324));
CHECK_EQ(4e-324, StrtodChar("3", -324));
// It would be more readable to put non-zero literals on the left side (i.e.
// CHECK_EQ(1e-325, StrtodChar("1", -325))), but then Gcc complains that
// they are truncated to zero.
CHECK_EQ(0.0, StrtodChar("1", -325));
CHECK_EQ(0.0, StrtodChar("1", -325));
CHECK_EQ(0.0, StrtodChar("20000", -328));
CHECK_EQ(40000e-328, StrtodChar("30000", -328));
CHECK_EQ(0.0, StrtodChar("10000", -329));
CHECK_EQ(0.0, StrtodChar("90000", -329));
CHECK_EQ(0.0, StrtodChar("000000001", -325));
CHECK_EQ(0.0, StrtodChar("000000001", -325));
CHECK_EQ(0.0, StrtodChar("0000000020000", -328));
CHECK_EQ(40000e-328, StrtodChar("00000030000", -328));
CHECK_EQ(0.0, StrtodChar("0000000010000", -329));
CHECK_EQ(0.0, StrtodChar("0000000090000", -329));
// It would be more readable to put the literals (and not Double::Infinity())
// on the left side (i.e. CHECK_EQ(1e309, StrtodChar("1", 309))), but then Gcc
// complains that the floating constant exceeds range of 'double'.
CHECK_EQ(Double::Infinity(), StrtodChar("1", 309));
CHECK_EQ(1e308, StrtodChar("1", 308));
CHECK_EQ(1234e305, StrtodChar("1234", 305));
CHECK_EQ(1234e304, StrtodChar("1234", 304));
CHECK_EQ(Double::Infinity(), StrtodChar("18", 307));
CHECK_EQ(17e307, StrtodChar("17", 307));
CHECK_EQ(Double::Infinity(), StrtodChar("0000001", 309));
CHECK_EQ(1e308, StrtodChar("00000001", 308));
CHECK_EQ(1234e305, StrtodChar("00000001234", 305));
CHECK_EQ(1234e304, StrtodChar("000000001234", 304));
CHECK_EQ(Double::Infinity(), StrtodChar("0000000018", 307));
CHECK_EQ(17e307, StrtodChar("0000000017", 307));
CHECK_EQ(Double::Infinity(), StrtodChar("1000000", 303));
CHECK_EQ(1e308, StrtodChar("100000", 303));
CHECK_EQ(1234e305, StrtodChar("123400000", 300));
CHECK_EQ(1234e304, StrtodChar("123400000", 299));
CHECK_EQ(Double::Infinity(), StrtodChar("180000000", 300));
CHECK_EQ(17e307, StrtodChar("170000000", 300));
CHECK_EQ(Double::Infinity(), StrtodChar("00000001000000", 303));
CHECK_EQ(1e308, StrtodChar("000000000000100000", 303));
CHECK_EQ(1234e305, StrtodChar("00000000123400000", 300));
CHECK_EQ(1234e304, StrtodChar("0000000123400000", 299));
CHECK_EQ(Double::Infinity(), StrtodChar("00000000180000000", 300));
CHECK_EQ(17e307, StrtodChar("00000000170000000", 300));
CHECK_EQ(1.7976931348623157E+308, StrtodChar("17976931348623157", 292));
CHECK_EQ(1.7976931348623158E+308, StrtodChar("17976931348623158", 292));
CHECK_EQ(Double::Infinity(), StrtodChar("17976931348623159", 292));
// The following number is the result of 89255.0/1e-22. Both floating-point
// numbers can be accurately represented with doubles. However on Linux,x86
// the floating-point stack is set to 80bits and the double-rounding
// introduces an error.
CHECK_EQ(89255e-22, StrtodChar("89255", -22));
// Some random values.
CHECK_EQ(358416272e-33, StrtodChar("358416272", -33));
CHECK_EQ(104110013277974872254e-225,
StrtodChar("104110013277974872254", -225));
CHECK_EQ(123456789e108, StrtodChar("123456789", 108));
CHECK_EQ(123456789e109, StrtodChar("123456789", 109));
CHECK_EQ(123456789e110, StrtodChar("123456789", 110));
CHECK_EQ(123456789e111, StrtodChar("123456789", 111));
CHECK_EQ(123456789e112, StrtodChar("123456789", 112));
CHECK_EQ(123456789e113, StrtodChar("123456789", 113));
CHECK_EQ(123456789e114, StrtodChar("123456789", 114));
CHECK_EQ(123456789e115, StrtodChar("123456789", 115));
CHECK_EQ(1234567890123456789012345e108,
StrtodChar("1234567890123456789012345", 108));
CHECK_EQ(1234567890123456789012345e109,
StrtodChar("1234567890123456789012345", 109));
CHECK_EQ(1234567890123456789012345e110,
StrtodChar("1234567890123456789012345", 110));
CHECK_EQ(1234567890123456789012345e111,
StrtodChar("1234567890123456789012345", 111));
CHECK_EQ(1234567890123456789012345e112,
StrtodChar("1234567890123456789012345", 112));
CHECK_EQ(1234567890123456789012345e113,
StrtodChar("1234567890123456789012345", 113));
CHECK_EQ(1234567890123456789012345e114,
StrtodChar("1234567890123456789012345", 114));
CHECK_EQ(1234567890123456789012345e115,
StrtodChar("1234567890123456789012345", 115));
CHECK_EQ(1234567890123456789052345e108,
StrtodChar("1234567890123456789052345", 108));
CHECK_EQ(1234567890123456789052345e109,
StrtodChar("1234567890123456789052345", 109));
CHECK_EQ(1234567890123456789052345e110,
StrtodChar("1234567890123456789052345", 110));
CHECK_EQ(1234567890123456789052345e111,
StrtodChar("1234567890123456789052345", 111));
CHECK_EQ(1234567890123456789052345e112,
StrtodChar("1234567890123456789052345", 112));
CHECK_EQ(1234567890123456789052345e113,
StrtodChar("1234567890123456789052345", 113));
CHECK_EQ(1234567890123456789052345e114,
StrtodChar("1234567890123456789052345", 114));
CHECK_EQ(1234567890123456789052345e115,
StrtodChar("1234567890123456789052345", 115));
CHECK_EQ(5.445618932859895e-255,
StrtodChar("5445618932859895362967233318697132813618813095743952975"
"4392982234069699615600475529427176366709107287468930197"
"8628345413991790019316974825934906752493984055268219809"
"5012176093045431437495773903922425632551857520884625114"
"6241265881735209066709685420744388526014389929047617597"
"0302268848374508109029268898695825171158085457567481507"
"4162979705098246243690189880319928315307816832576838178"
"2563074014542859888710209237525873301724479666744537857"
"9026553346649664045621387124193095870305991178772256504"
"4368663670643970181259143319016472430928902201239474588"
"1392338901353291306607057623202353588698746085415097902"
"6640064319118728664842287477491068264828851624402189317"
"2769161449825765517353755844373640588822904791244190695"
"2998382932630754670573838138825217065450843010498555058"
"88186560731", -1035));
// Boundary cases. Boundaries themselves should round to even.
//
// 0x1FFFFFFFFFFFF * 2^3 = 72057594037927928
// next: 72057594037927936
// boundary: 72057594037927932 should round up.
CHECK_EQ(72057594037927928.0, StrtodChar("72057594037927928", 0));
CHECK_EQ(72057594037927936.0, StrtodChar("72057594037927936", 0));
CHECK_EQ(72057594037927936.0, StrtodChar("72057594037927932", 0));
CHECK_EQ(72057594037927928.0, StrtodChar("7205759403792793199999", -5));
CHECK_EQ(72057594037927936.0, StrtodChar("7205759403792793200001", -5));
// 0x1FFFFFFFFFFFF * 2^10 = 9223372036854774784
// next: 9223372036854775808
// boundary: 9223372036854775296 should round up.
CHECK_EQ(9223372036854774784.0, StrtodChar("9223372036854774784", 0));
CHECK_EQ(9223372036854775808.0, StrtodChar("9223372036854775808", 0));
CHECK_EQ(9223372036854775808.0, StrtodChar("9223372036854775296", 0));
CHECK_EQ(9223372036854774784.0, StrtodChar("922337203685477529599999", -5));
CHECK_EQ(9223372036854775808.0, StrtodChar("922337203685477529600001", -5));
// 0x1FFFFFFFFFFFF * 2^50 = 10141204801825834086073718800384
// next: 10141204801825835211973625643008
// boundary: 10141204801825834649023672221696 should round up.
CHECK_EQ(10141204801825834086073718800384.0,
StrtodChar("10141204801825834086073718800384", 0));
CHECK_EQ(10141204801825835211973625643008.0,
StrtodChar("10141204801825835211973625643008", 0));
CHECK_EQ(10141204801825835211973625643008.0,
StrtodChar("10141204801825834649023672221696", 0));
CHECK_EQ(10141204801825834086073718800384.0,
StrtodChar("1014120480182583464902367222169599999", -5));
CHECK_EQ(10141204801825835211973625643008.0,
StrtodChar("1014120480182583464902367222169600001", -5));
// 0x1FFFFFFFFFFFF * 2^99 = 5708990770823838890407843763683279797179383808
// next: 5708990770823839524233143877797980545530986496
// boundary: 5708990770823839207320493820740630171355185152
// The boundary should round up.
CHECK_EQ(5708990770823838890407843763683279797179383808.0,
StrtodChar("5708990770823838890407843763683279797179383808", 0));
CHECK_EQ(5708990770823839524233143877797980545530986496.0,
StrtodChar("5708990770823839524233143877797980545530986496", 0));
CHECK_EQ(5708990770823839524233143877797980545530986496.0,
StrtodChar("5708990770823839207320493820740630171355185152", 0));
CHECK_EQ(5708990770823838890407843763683279797179383808.0,
StrtodChar("5708990770823839207320493820740630171355185151999", -3));
CHECK_EQ(5708990770823839524233143877797980545530986496.0,
StrtodChar("5708990770823839207320493820740630171355185152001", -3));
// The following test-cases got some public attention in early 2011 when they
// sent Java and PHP into an infinite loop.
CHECK_EQ(2.225073858507201e-308, StrtodChar("22250738585072011", -324));
CHECK_EQ(2.22507385850720138309e-308,
StrtodChar("22250738585072011360574097967091319759348195463516456480"
"23426109724822222021076945516529523908135087914149158913"
"03962110687008643869459464552765720740782062174337998814"
"10632673292535522868813721490129811224514518898490572223"
"07285255133155755015914397476397983411801999323962548289"
"01710708185069063066665599493827577257201576306269066333"
"26475653000092458883164330377797918696120494973903778297"
"04905051080609940730262937128958950003583799967207254304"
"36028407889577179615094551674824347103070260914462157228"
"98802581825451803257070188608721131280795122334262883686"
"22321503775666622503982534335974568884423900265498198385"
"48794829220689472168983109969836584681402285424333066033"
"98508864458040010349339704275671864433837704860378616227"
"71738545623065874679014086723327636718751", -1076));
}
TEST(Strtof) {
Vector<const char> vector;
vector = StringToVector("0");
CHECK_EQ(0.0f, Strtof(vector, 1));
CHECK_EQ(0.0f, Strtof(vector, 2));
CHECK_EQ(0.0f, Strtof(vector, -2));
CHECK_EQ(0.0f, Strtof(vector, -999));
CHECK_EQ(0.0f, Strtof(vector, +999));
vector = StringToVector("1");
CHECK_EQ(1.0f, Strtof(vector, 0));
CHECK_EQ(10.0f, Strtof(vector, 1));
CHECK_EQ(100.0f, Strtof(vector, 2));
CHECK_EQ(1e20f, Strtof(vector, 20));
CHECK_EQ(1e22f, Strtof(vector, 22));
CHECK_EQ(1e23f, Strtof(vector, 23));
CHECK_EQ(1e35f, Strtof(vector, 35));
CHECK_EQ(1e36f, Strtof(vector, 36));
CHECK_EQ(1e37f, Strtof(vector, 37));
CHECK_EQ(1e-1f, Strtof(vector, -1));
CHECK_EQ(1e-2f, Strtof(vector, -2));
CHECK_EQ(1e-5f, Strtof(vector, -5));
CHECK_EQ(1e-20f, Strtof(vector, -20));
CHECK_EQ(1e-22f, Strtof(vector, -22));
CHECK_EQ(1e-23f, Strtof(vector, -23));
CHECK_EQ(1e-25f, Strtof(vector, -25));
CHECK_EQ(1e-39f, Strtof(vector, -39));
vector = StringToVector("2");
CHECK_EQ(2.0f, Strtof(vector, 0));
CHECK_EQ(20.0f, Strtof(vector, 1));
CHECK_EQ(200.0f, Strtof(vector, 2));
CHECK_EQ(2e20f, Strtof(vector, 20));
CHECK_EQ(2e22f, Strtof(vector, 22));
CHECK_EQ(2e23f, Strtof(vector, 23));
CHECK_EQ(2e35f, Strtof(vector, 35));
CHECK_EQ(2e36f, Strtof(vector, 36));
CHECK_EQ(2e37f, Strtof(vector, 37));
CHECK_EQ(2e-1f, Strtof(vector, -1));
CHECK_EQ(2e-2f, Strtof(vector, -2));
CHECK_EQ(2e-5f, Strtof(vector, -5));
CHECK_EQ(2e-20f, Strtof(vector, -20));
CHECK_EQ(2e-22f, Strtof(vector, -22));
CHECK_EQ(2e-23f, Strtof(vector, -23));
CHECK_EQ(2e-25f, Strtof(vector, -25));
CHECK_EQ(2e-39f, Strtof(vector, -39));
vector = StringToVector("9");
CHECK_EQ(9.0f, Strtof(vector, 0));
CHECK_EQ(90.0f, Strtof(vector, 1));
CHECK_EQ(900.0f, Strtof(vector, 2));
CHECK_EQ(9e20f, Strtof(vector, 20));
CHECK_EQ(9e22f, Strtof(vector, 22));
CHECK_EQ(9e23f, Strtof(vector, 23));
CHECK_EQ(9e35f, Strtof(vector, 35));
CHECK_EQ(9e36f, Strtof(vector, 36));
CHECK_EQ(9e37f, Strtof(vector, 37));
CHECK_EQ(9e-1f, Strtof(vector, -1));
CHECK_EQ(9e-2f, Strtof(vector, -2));
CHECK_EQ(9e-5f, Strtof(vector, -5));
CHECK_EQ(9e-20f, Strtof(vector, -20));
CHECK_EQ(9e-22f, Strtof(vector, -22));
CHECK_EQ(9e-23f, Strtof(vector, -23));
CHECK_EQ(9e-25f, Strtof(vector, -25));
CHECK_EQ(9e-39f, Strtof(vector, -39));
vector = StringToVector("12345");
CHECK_EQ(12345.0f, Strtof(vector, 0));
CHECK_EQ(123450.0f, Strtof(vector, 1));
CHECK_EQ(1234500.0f, Strtof(vector, 2));
CHECK_EQ(12345e20f, Strtof(vector, 20));
CHECK_EQ(12345e22f, Strtof(vector, 22));
CHECK_EQ(12345e23f, Strtof(vector, 23));
CHECK_EQ(12345e30f, Strtof(vector, 30));
CHECK_EQ(12345e31f, Strtof(vector, 31));
CHECK_EQ(12345e32f, Strtof(vector, 32));
CHECK_EQ(12345e-1f, Strtof(vector, -1));
CHECK_EQ(12345e-2f, Strtof(vector, -2));
CHECK_EQ(12345e-5f, Strtof(vector, -5));
CHECK_EQ(12345e-20f, Strtof(vector, -20));
CHECK_EQ(12345e-22f, Strtof(vector, -22));
CHECK_EQ(12345e-23f, Strtof(vector, -23));
CHECK_EQ(12345e-25f, Strtof(vector, -25));
CHECK_EQ(12345e-39f, Strtof(vector, -39));
vector = StringToVector("12345678901234");
CHECK_EQ(12345678901234.0f, Strtof(vector, 0));
CHECK_EQ(123456789012340.0f, Strtof(vector, 1));
CHECK_EQ(1234567890123400.0f, Strtof(vector, 2));
CHECK_EQ(12345678901234e20f, Strtof(vector, 20));
CHECK_EQ(12345678901234e22f, Strtof(vector, 22));
CHECK_EQ(12345678901234e23f, Strtof(vector, 23));
CHECK_EQ(12345678901234e-1f, Strtof(vector, -1));
CHECK_EQ(12345678901234e-2f, Strtof(vector, -2));
CHECK_EQ(12345678901234e-5f, Strtof(vector, -5));
CHECK_EQ(12345678901234e-20f, Strtof(vector, -20));
CHECK_EQ(12345678901234e-22f, Strtof(vector, -22));
CHECK_EQ(12345678901234e-23f, Strtof(vector, -23));
CHECK_EQ(12345678901234e-25f, Strtof(vector, -25));
CHECK_EQ(12345678901234e-39f, Strtof(vector, -39));
vector = StringToVector("123456789012345");
CHECK_EQ(123456789012345.0f, Strtof(vector, 0));
CHECK_EQ(1234567890123450.0f, Strtof(vector, 1));
CHECK_EQ(12345678901234500.0f, Strtof(vector, 2));
CHECK_EQ(123456789012345e20f, Strtof(vector, 20));
CHECK_EQ(123456789012345e22f, Strtof(vector, 22));
CHECK_EQ(123456789012345e23f, Strtof(vector, 23));
CHECK_EQ(123456789012345e-1f, Strtof(vector, -1));
CHECK_EQ(123456789012345e-2f, Strtof(vector, -2));
CHECK_EQ(123456789012345e-5f, Strtof(vector, -5));
CHECK_EQ(123456789012345e-20f, Strtof(vector, -20));
CHECK_EQ(123456789012345e-22f, Strtof(vector, -22));
CHECK_EQ(123456789012345e-23f, Strtof(vector, -23));
CHECK_EQ(123456789012345e-25f, Strtof(vector, -25));
CHECK_EQ(123456789012345e-39f, Strtof(vector, -39));
CHECK_EQ(0.0f, StrtofChar("0", 12345));
CHECK_EQ(0.0f, StrtofChar("", 1324));
CHECK_EQ(0.0f, StrtofChar("000000000", 123));
CHECK_EQ(0.0f, StrtofChar("2", -324));
CHECK_EQ(1e-45f, StrtofChar("1", -45));
// It would be more readable to put non-zero literals on the left side (i.e.
// CHECK_EQ(1e-46, StrtofChar("1", -45))), but then Gcc complains that
// they are truncated to zero.
CHECK_EQ(0.0f, StrtofChar("1", -46));
CHECK_EQ(0.0f, StrtofChar("1", -47));
CHECK_EQ(1e-45f, StrtofChar("1", -45));
CHECK_EQ(1e-45f, StrtofChar("8", -46));
CHECK_EQ(0.0f, StrtofChar("200000", -51));
CHECK_EQ(100000e-50f, StrtofChar("100000", -50));
CHECK_EQ(0.0f, StrtofChar("100000", -51));
CHECK_EQ(0.0f, StrtofChar("900000", -52));
CHECK_EQ(0.0f, StrtofChar("000000001", -47));
CHECK_EQ(0.0f, StrtofChar("000000001", -47));
CHECK_EQ(0.0f, StrtofChar("00000000200000", -51));
CHECK_EQ(800000e-50f, StrtofChar("000000800000", -50));
CHECK_EQ(0.0f, StrtofChar("00000000100000", -51));
CHECK_EQ(1e-45f, StrtofChar("00000000900000", -51));
// It would be more readable to put the literals (and not Double::Infinity())
// on the left side (i.e. CHECK_EQ(3e38, StrtofChar("3", 38))), but then Gcc
// complains that the floating constant exceeds range of 'double'.
CHECK_EQ(Single::Infinity(), StrtofChar("3", 39));
CHECK_EQ(3e38f, StrtofChar("3", 38));
CHECK_EQ(3401e35f, StrtofChar("3401", 35));
CHECK_EQ(3401e34f, StrtofChar("3401", 34));
CHECK_EQ(Single::Infinity(), StrtofChar("3410", 35));
CHECK_EQ(34e37f, StrtofChar("34", 37));
CHECK_EQ(Single::Infinity(), StrtofChar("0000001", 39));
CHECK_EQ(3401e35f, StrtofChar("0000003401", 35));
CHECK_EQ(3401e34f, StrtofChar("0000003401", 34));
CHECK_EQ(Single::Infinity(), StrtofChar("0000003410", 35));
CHECK_EQ(34e37f, StrtofChar("00000034", 37));
CHECK_EQ(1e38f, StrtofChar("100000", 33));
CHECK_EQ(3401e35f, StrtofChar("340100000", 30));
CHECK_EQ(3401e34f, StrtofChar("340100000", 29));
CHECK_EQ(Single::Infinity(), StrtofChar("341000000", 30));
CHECK_EQ(34e37f, StrtofChar("3400000", 32));
CHECK_EQ(1e38f, StrtofChar("00000100000", 33));
CHECK_EQ(3401e35f, StrtofChar("00000340100000", 30));
CHECK_EQ(3401e34f, StrtofChar("00000340100000", 29));
CHECK_EQ(Single::Infinity(), StrtofChar("00000341000000", 30));
CHECK_EQ(34e37f, StrtofChar("000003400000", 32));
CHECK_EQ(3.4028234e+38f, StrtofChar("34028235676", 28));
CHECK_EQ(3.4028234e+38f, StrtofChar("34028235677", 28));
CHECK_EQ(Single::Infinity(), StrtofChar("34028235678", 28));
// The following number is the result of 89255.0/1e-22. Both floating-point
// numbers can be accurately represented with doubles. However on Linux,x86
// the floating-point stack is set to 80bits and the double-rounding
// introduces an error.
CHECK_EQ(89255e-22f, StrtofChar("89255", -22));
// Boundary cases. Boundaries themselves should round to even.
//
// 0x4f012334 = 2166567936
// next: 2166568192
// boundary: 2166568064 should round down.
CHECK_EQ(2166567936.0f, StrtofChar("2166567936", 0));
CHECK_EQ(2166568192.0f, StrtofChar("2166568192", 0));
CHECK_EQ(2166567936.0f, StrtofChar("2166568064", 0));
CHECK_EQ(2166567936.0f, StrtofChar("216656806399999", -5));
CHECK_EQ(2166568192.0f, StrtofChar("216656806400001", -5));
// Verify that we don't double round.
// Get the boundary of the boundary.
CHECK_EQ(2.1665680640000002384185791015625e9, 2166568064.0);
// Visual Studio gets this wrong and believes that these two numbers are the
// same doubles. We want to test our conversion and not the compiler. We
// therefore disable the check.
#ifndef _MSC_VER
CHECK(2.16656806400000023841857910156251e9 != 2166568064.0);
#endif
CHECK_EQ(2166568192.0f, StrtofChar("21665680640000002384185791015625", -22));
// 0x4fffffff = 8589934080
// next: 8589934592
// boundary: 8589934336 should round up.
CHECK_EQ(8589934080.0f, StrtofChar("8589934080", 0));
CHECK_EQ(8589934592.0f, StrtofChar("8589934592", 0));
CHECK_EQ(8589934592.0f, StrtofChar("8589934336", 0));
CHECK_EQ(8589934080.0f, StrtofChar("858993433599999", -5));
CHECK_EQ(8589934592.0f, StrtofChar("858993433600001", -5));
// Verify that we don't double round.
// Get the boundary of the boundary.
// Visual Studio gets this wrong. To avoid failing tests because of a broken
// compiler we disable the following two tests. They were only testing the
// compiler. The real test is still active.
#ifndef _MSC_VER
CHECK_EQ(8.589934335999999523162841796875e+09, 8589934336.0);
CHECK(8.5899343359999995231628417968749e+09 != 8589934336.0);
#endif
CHECK_EQ(8589934080.0f, StrtofChar("8589934335999999523162841796875", -21));
// 0x4f000000 = 2147483648
// next: 2147483904
// boundary: 2147483776 should round down.
CHECK_EQ(2147483648.0f, StrtofChar("2147483648", 0));
CHECK_EQ(2147483904.0f, StrtofChar("2147483904", 0));
CHECK_EQ(2147483648.0f, StrtofChar("2147483776", 0));
CHECK_EQ(2147483648.0f, StrtofChar("214748377599999", -5));
CHECK_EQ(2147483904.0f, StrtofChar("214748377600001", -5));
}
static int CompareBignumToDiyFp(const Bignum& bignum_digits,
int bignum_exponent,
DiyFp diy_fp) {
Bignum bignum;
bignum.AssignBignum(bignum_digits);
Bignum other;
other.AssignUInt64(diy_fp.f());
if (bignum_exponent >= 0) {
bignum.MultiplyByPowerOfTen(bignum_exponent);
} else {
other.MultiplyByPowerOfTen(-bignum_exponent);
}
if (diy_fp.e() >= 0) {
other.ShiftLeft(diy_fp.e());
} else {
bignum.ShiftLeft(-diy_fp.e());
}
return Bignum::Compare(bignum, other);
}
static bool CheckDouble(Vector<const char> buffer,
int exponent,
double to_check) {
DiyFp lower_boundary;
DiyFp upper_boundary;
Bignum input_digits;
input_digits.AssignDecimalString(buffer);
if (to_check == 0.0) {
const double kMinDouble = 4e-324;
// Check that the buffer*10^exponent < (0 + kMinDouble)/2.
Double d(kMinDouble);
d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0;
}
if (to_check == Double::Infinity()) {
const double kMaxDouble = 1.7976931348623157e308;
// Check that the buffer*10^exponent >= boundary between kMaxDouble and inf.
Double d(kMaxDouble);
d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0;
}
Double d(to_check);
d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
if ((d.Significand() & 1) == 0) {
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) >= 0 &&
CompareBignumToDiyFp(input_digits, exponent, upper_boundary) <= 0;
} else {
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) > 0 &&
CompareBignumToDiyFp(input_digits, exponent, upper_boundary) < 0;
}
}
// Copied from v8.cc and adapted to make the function deterministic.
static uint32_t DeterministicRandom() {
// Random number generator using George Marsaglia's MWC algorithm.
static uint32_t hi = 0;
static uint32_t lo = 0;
// Initialization values don't have any special meaning. (They are the result
// of two calls to random().)
if (hi == 0) hi = 0xbfe166e7;
if (lo == 0) lo = 0x64d1c3c9;
// Mix the bits.
hi = 36969 * (hi & 0xFFFF) + (hi >> 16);
lo = 18273 * (lo & 0xFFFF) + (lo >> 16);
return (hi << 16) + (lo & 0xFFFF);
}
static const int kBufferSize = 1024;
static const int kShortStrtodRandomCount = 2;
static const int kLargeStrtodRandomCount = 2;
TEST(RandomStrtod) {
char buffer[kBufferSize];
for (int length = 1; length < 15; length++) {
for (int i = 0; i < kShortStrtodRandomCount; ++i) {
int pos = 0;
for (int j = 0; j < length; ++j) {
buffer[pos++] = DeterministicRandom() % 10 + '0';
}
int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length;
buffer[pos] = '\0';
Vector<const char> vector(buffer, pos);
double strtod_result = Strtod(vector, exponent);
CHECK(CheckDouble(vector, exponent, strtod_result));
}
}
for (int length = 15; length < 800; length += 2) {
for (int i = 0; i < kLargeStrtodRandomCount; ++i) {
int pos = 0;
for (int j = 0; j < length; ++j) {
buffer[pos++] = DeterministicRandom() % 10 + '0';
}
int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length;
buffer[pos] = '\0';
Vector<const char> vector(buffer, pos);
double strtod_result = Strtod(vector, exponent);
CHECK(CheckDouble(vector, exponent, strtod_result));
}
}
}
static bool CheckFloat(Vector<const char> buffer,
int exponent,
float to_check) {
DiyFp lower_boundary;
DiyFp upper_boundary;
Bignum input_digits;
input_digits.AssignDecimalString(buffer);
if (to_check == 0.0) {
const float kMinFloat = 1e-45f;
// Check that the buffer*10^exponent < (0 + kMinFloat)/2.
Single s(kMinFloat);
s.NormalizedBoundaries(&lower_boundary, &upper_boundary);
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0;
}
if (to_check == static_cast<float>(Double::Infinity())) {
const float kMaxFloat = 3.4028234e38f;
// Check that the buffer*10^exponent >= boundary between kMaxFloat and inf.
Single s(kMaxFloat);
s.NormalizedBoundaries(&lower_boundary, &upper_boundary);
return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0;
}
Single s(to_check);
s.NormalizedBoundaries(&lower_boundary, &upper_boundary);
if ((s.Significand() & 1) == 0) {
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) >= 0 &&
CompareBignumToDiyFp(input_digits, exponent, upper_boundary) <= 0;
} else {
return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) > 0 &&
CompareBignumToDiyFp(input_digits, exponent, upper_boundary) < 0;
}
}
static const int kShortStrtofRandomCount = 2;
static const int kLargeStrtofRandomCount = 2;
TEST(RandomStrtof) {
char buffer[kBufferSize];
for (int length = 1; length < 15; length++) {
for (int i = 0; i < kShortStrtofRandomCount; ++i) {
int pos = 0;
for (int j = 0; j < length; ++j) {
buffer[pos++] = DeterministicRandom() % 10 + '0';
}
int exponent = DeterministicRandom() % (5*2 + 1) - 5 - length;
buffer[pos] = '\0';
Vector<const char> vector(buffer, pos);
float strtof_result = Strtof(vector, exponent);
CHECK(CheckFloat(vector, exponent, strtof_result));
}
}
for (int length = 15; length < 800; length += 2) {
for (int i = 0; i < kLargeStrtofRandomCount; ++i) {
int pos = 0;
for (int j = 0; j < length; ++j) {
buffer[pos++] = DeterministicRandom() % 10 + '0';
}
int exponent = DeterministicRandom() % (38*2 + 1) - 38 - length;
buffer[pos] = '\0';
Vector<const char> vector(buffer, pos);
float strtof_result = Strtof(vector, exponent);
CHECK(CheckFloat(vector, exponent, strtof_result));
}
}
}

Binary file not shown.

Binary file not shown.