Skip to content

Commit

Permalink
Merge pull request #30 from meokullu/new_version_0001
Browse files Browse the repository at this point in the history
v1.4.0 conversion methods added for int32, int64 and double.
  • Loading branch information
meokullu committed May 29, 2024
2 parents ac74b3e + 696a3d2 commit 65201c8
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/desktop.ini
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#### Removed
-->

### [1.4.0]
#### Added
* `ToInt32(string data, int startingIndex, int endIndex)` method added to convert string numerical data into int32 data type.
* `ToInt64(string data, int startingIndex, int endIndex)` method added to convert string numerical data into int64 data type.
* `ToDouble(string data, int startingIndex, int endIndex)` method added to convert string numerical data into double data type.

#### Changed
* Numerical data moved to data.cs under src folder in order to increase exploring performance due to high amount of data.

### [1.3.4]
#### Changed
* Number data moved to `data.cs` which is under `src` folder.
Expand Down
106 changes: 102 additions & 4 deletions MathematicalConstants/MathematicalConstants.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,112 @@
using static MathematicalConstants.MathematicalConstants;
using System;
using System.Text;

namespace MathmeticalConstants
namespace MathematicalConstants
{
/// <summary>
/// Mathmetical Constants Helpers
/// </summary>
public partial class MathematicalConstants
{
/// <summary>
/// Convert string data to int32.
/// </summary>
/// <param name="data">String format of data provided by MathematicalConstants.</param>
/// <param name="startIndex">Starting index. Must be higher than 1.</param>
/// <param name="endIndex">Ending index. Must be equal or higher than startingIndex.</param>
/// <returns>integer of conversion.</returns>
/// <exception cref="Exception">Throws exception if startingIndex and endingIndex is negative. Throws exception if endIndex is lower than startIndex. Throws exception if startIndex is lower than 1. Throws exception if converted data overflows int32.</exception>
public static int ToInt32(string data, int startIndex, int endIndex)
{
if (startIndex < 0 && endIndex < 0)
{
throw new Exception("startIndex and endIndex must be positive numbers.");
}

if (endIndex < startIndex)
{
throw new Exception("endIndex must be higher than startIndex");
}

if (startIndex < 1)
{
throw new Exception("startIndex must be higher than in order to return integer data.");
}

int.TryParse(data.Substring(startIndex, (endIndex-startIndex)), out int result);

return result;
}

/// <summary>
/// Convert string data to int64.
/// </summary>
/// <param name="data">String format of data provided by MathematicalConstants.</param>
/// <param name="startIndex">Starting index. Must be higher than 1.</param>
/// <param name="endIndex">Ending index. Must be equal or higher than startingIndex.</param>
/// <returns>integer of conversion.</returns>
/// <exception cref="Exception">Throws exception if startingIndex and endingIndex is negative. Throws exception if endIndex is lower than startIndex. Throws exception if startIndex is lower than 1. Throws exception if converted data overflows int64.</exception>
public static long ToInt64(string data, int startIndex, int endIndex)
{
if (startIndex < 0 && endIndex < 0)
{
throw new Exception("startIndex and endIndex must be positive numbers.");
}

if (endIndex < startIndex)
{
throw new Exception("endIndex must be higher than startIndex");
}

if (startIndex < 1)
{
throw new Exception("startIndex must be higher than in order to return integer data.");
}

long.TryParse(data.Substring(startIndex, (endIndex-startIndex)), out long result);

return result;
}

/// <summary>
/// Convert string data to double.
/// </summary>
/// <param name="data">String format of data provided by MathematicalConstants.</param>
/// <param name="startIndex">Starting index.</param>
/// <param name="endIndex">Ending index. Must be equal or higher than startingIndex.</param>
/// <returns>integer of conversion.</returns>
/// <exception cref="Exception">Throws exception if startingIndex and endingIndex is negative. Throws exception if endIndex is lower than startIndex. Throws exception if converted data overflows int32.</exception>
public static double ToDouble(string data, int startIndex, int endIndex)
{
if (startIndex < 0 && endIndex < 0)
{
throw new Exception("startIndex and endIndex must be positive numbers.");
}

if (endIndex < startIndex)
{
throw new Exception("endIndex must be higher than startIndex");
}

double result;

if (startIndex < 1)
{
StringBuilder sb = new StringBuilder();
sb.Append(data.Substring(startIndex, (endIndex - startIndex)));

sb.Insert(1, ".");

double.TryParse(sb.ToString(), out result);
}
else
{
double.TryParse(data.Substring(startIndex, (endIndex - startIndex)), out result);
}

return result;
}

/// <summary>
/// Maximum available digits of number Phi. "1.6180..."
/// </summary>
Expand Down Expand Up @@ -412,6 +512,4 @@ public partial class MathematicalConstants
/// </summary>
public static int LengthWeierstrass => Weierstrass.Length;
}


}
17 changes: 11 additions & 6 deletions MathematicalConstants/MathematicalConstants.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
<ImplicitUsings>disable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>Mathematical Constants</Title>
<Version>1.3.4</Version>
<Version>1.4.0</Version>
<Authors>Enes Okullu</Authors>
<Description>Mathematical Constants is a library, offers 82 mathematical constants upto one million digit on string format.</Description>
<Copyright>Enes Okullu</Copyright>
<PackageTags>Math; Mathematical; Numbers; Constants;</PackageTags>
<PackageReleaseNotes>
v1.3.4
Data moved to data.cs under src folder.

v1.4.0
* ToInt32(string data, int startingIndex, int endIndex) method added to convert string numerical data into int32 data type.
* ToInt64(string data, int startingIndex, int endIndex) method added to convert string numerical data into int64 data type.
* ToDouble(string data, int startingIndex, int endIndex) method added to convert string numerical data into double data type.

#### Changed
* Numerical data moved to data.cs under src folder in order to increase exploring performance due to high amount of data.

See changelog (https://github.com/meokullu/MathematicalConstants/blob/master/CHANGELOG.md)
</PackageReleaseNotes>
<AssemblyVersion>1.3.4</AssemblyVersion>
<FileVersion>1.3.4</FileVersion>
<AssemblyVersion>1.4.0</AssemblyVersion>
<FileVersion>1.4.0</FileVersion>
<PackageLicenseFile>LICENCE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/meokullu/MathematicalConstants</RepositoryUrl>
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ String formatted mathematical constants are presented with their Wikipedia link,
| Weierstrass | 0.4749 | [Weierstrass](https://en.wikipedia.org/wiki/Weierstrass) | https://oeis.org/A094692 | [Wikipedia](https://en.wikipedia.org/wiki/Weierstrass) |

### Example Usage
```
ToDouble(PiNumber, 0, 5); // returns 3.1415
```

```
ToInt32(ENumber, 1, 7); // return 71828 (from 2.71828...)
```

```
ToInt64(PhiNumber, 1, 10); // return 618033988 (from 1618033988...)
```

### Version History
See [Changelog](https://github.com/meokullu/MathematicalConstants/blob/master/CHANGELOG.md)
Expand All @@ -109,4 +120,4 @@ If you'd like to contribute, then contribute. [contributing guide](https://githu
[![Contributors](https://contrib.rocks/image?repo=meokullu/MathematicalConstants)](https://github.com/meokullu/MathematicalConstants/graphs/contributors)

### Help
Twitter: Enes Okullu [@enesokullu](https://twitter.com/EnesOkullu)
Twitter: Enes Okullu [@enesokullu](https://twitter.com/EnesOkullu)

0 comments on commit 65201c8

Please sign in to comment.