Git Product home page Git Product logo

bigdecimal's People

Contributors

adamwhitehat avatar bykiev avatar pixelatedlagg avatar protiguous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bigdecimal's Issues

BUG: incorrect parsing with non-dot decimal separator

Description
When rounding the value with culture where decimal separator is comma an error has occured.

Error/Exception Message
System.FormatException: "The value could not be parsed."

в System.Numerics.BigNumber.ParseBigInteger(ReadOnlySpan`1 value, NumberStyles style, NumberFormatInfo info)
   в System.Numerics.BigNumber.ParseBigInteger(String value, NumberStyles style, NumberFormatInfo info)
   в ExtendedNumerics.BigDecimal.GetWholePart()
   в ExtendedNumerics.BigDecimal.Round(BigDecimal value, MidpointRounding mode)

Expected Behavior
The value should be correctly parsed

Actual Behavior
An error has occured: System.FormatException: "The value could not be parsed."

Steps To Reproduce

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ",";

var res = new BigDecimal(17.56);
var e = BigDecimal.Round(res, MidpointRounding.AwayFromZero);

BUG: Version 2025.1000.0.118 dlls are all versioned 0.0.0.0

Description
A clear and concise description of what the bug is.

Error/Exception Message
We updated to the latest package from nuget.org which is 2025.1000.0.118. This caused lots of issues with binding redirects in app.config/web.config files in legacy applications. Visual Studio set them all to

<dependentAssembly>
    <assemblyIdentity name="ExtendedNumerics.BigDecimal" culture="neutral" publicKeyToken="65f1315a45ad8949" />
    <bindingRedirect oldVersion="0.0.0.0-0.0.0.0" newVersion="0.0.0.0" />
</dependentAssembly>

Expected Behavior
Dlls in package should be version 2025.1000.0.118

Actual Behavior
Dlls in package are versioned 0.0.0.0

Steps To Reproduce
Use a package explorer or JetBrains dotPeek to inspect the package. Open any dll listed and they all state 0.0.0.0 as their version.

Screenshots
image

Do we still want to keep the .NET 5 as an option?

I'm now seeing this warning on compile in my experimental branch.

warning NETSDK1138: The target framework 'net5.0' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy.

Microsoft's Download .NET 5.0 reads:

This release has reached end of life, meaning it is no longer supported. We recommend moving to a supported release, such as .NET 7.0. See our support policy for more details.

I don't see any problem with leaving it available, except for the possibility that a security flaw might be discovered in .NET 5.
I will continue to work with .NET 5 until I hear otherwise.

BUG: [Title for your bug]

I don't think your nuget package is configured correctly.

When I install it, I cannot reference your:

var number1 = BigDecimal.Parse("1234567890");

I cannot locate your namespace BigDecimal.

Btw - I am using this library to count the number of decimal places. Its very helpful!! I looked here for code: https://stackoverflow.com/questions/13477689/find-number-of-decimal-places-in-decimal-value-regardless-of-culture/13477756#13477756 - due to the number of edge cases I decided to try your library <3 thanks!

No strong name for .NET Framework targets

Description
The library has no strong names and cannot be referenced from a Framework project.

Error/Exception Message
System.IO.FileLoadException

Expected Behavior
No exception.

Actual Behavior
Exception thrown.

Steps To Reproduce
Reference the NuGet package from a Framework project and use it.

Screenshots
image

Additional context/Comments/Notes/Rants
nissl-lab/npoi#1135 (comment)

Minor issue: "nu5035" after a Publish.

Description
I'm seeing the message, "The PackageLicenseUrl is being deprecated and cannot be used in conjunction with the PackageLicenseFile or PackageLicenseExpression." when I attempt to "Publish" to a local folder.

The source I'm using is over at: Protiguous - BigDecimal, experimental branch

Steps To Reproduce
Just tried a Publish to a temp folder on my machine while under the "Release" mode.

Additional Comments
Is this a real "issue"? Maybe something you know how to fix?
All I could find was at, "Microsoft Docs nu5035" and slightly less at "Nuget Reference".

BUG: converting to double results to 0

Description
When casting the BigDecimal variable to double the value is getting zero

Error/Exception Message
No

Expected Behavior
The value should be correctly converted to double

Actual Behavior
The value is getting zero

Steps To Reproduce

 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

 var temp = BigDecimal.Pow(10, -1);
 var value = new BigDecimal(99.00000001);
 var res = BigDecimal.Divide(value, temp);

 double res2 = (double)res;

BUG: BigDecimal.GetWholePart doesn't work for cultures that use `,` as a decimal separator

Description
The GetWholePart method doesn't set the culture info properly when converting the BigDecimal value to a string in order to split it by the . character. This causes the , to go through unmodified which causes errors further down the line with BigDecimal.Round for instance.

Error/Exception Message

E 0:00:54:0394   :0 @ void System.Numerics.BigNumber.ThrowOverflowOrFormatException(System.Numerics.BigNumber+ParsingStatus): System.FormatException: The value could not be parsed.
  <C++ Error>    System.FormatException
  <C++ Source>   :0 @ void System.Numerics.BigNumber.ThrowOverflowOrFormatException(System.Numerics.BigNumber+ParsingStatus)
  <Stack Trace>  :0 @ void System.Numerics.BigNumber.ThrowOverflowOrFormatException(System.Numerics.BigNumber+ParsingStatus)
                 :0 @ System.Numerics.BigInteger System.Numerics.BigNumber.ParseBigInteger(System.ReadOnlySpan`1[System.Char], System.Globalization.NumberStyles, System.Globalization.NumberFormatInfo)
                 :0 @ System.Numerics.BigInteger System.Numerics.BigNumber.ParseBigInteger(string, System.Globalization.NumberStyles, System.Globalization.NumberFormatInfo)
                 :0 @ System.Numerics.BigInteger System.Numerics.BigInteger.Parse(string, System.Globalization.NumberStyles, System.IFormatProvider)
                 :0 @ System.Numerics.BigInteger System.Numerics.BigInteger.Parse(string, System.Globalization.NumberStyles)
                 :0 @ System.Numerics.BigInteger System.Numerics.BigInteger.Parse(string)
                 :0 @ System.Numerics.BigInteger ExtendedNumerics.BigDecimal.GetWholePart()
                 :0 @ System.Numerics.BigInteger ExtendedNumerics.BigDecimal.get_WholeValue()
                 :0 @ System.Numerics.BigInteger ExtendedNumerics.BigDecimal.Round(ExtendedNumerics.BigDecimal, System.MidpointRounding)
                 :0 @ void TestGame.GameManager.GiveMergeBonusCoins(TestGame.Resources.MergeResource)
                 :0 @ void TestGame.GameManager.<HandleCountdown>b__65_2(TestGame.Resources.MergeResource)
                 :0 @ int TestGame.SectionManager.AutoMerge(System.Action`2[TestGame.MergeableObject,TestGame.MergeableObject], System.Action`1[TestGame.Resources.MergeResource])
                 :0 @ void TestGame.GameManager.HandleCountdown(float)
                 :0 @ void TestGame.GameManager._Process(double)
                 :0 @ bool Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
                 :0 @ bool TestGame.GameManager.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name&, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
                 :0 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(nint, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant_call_error*, Godot.NativeInterop.godot_variant*)

Full stacktrace from Godot, already found the root cause though at the BigDecimal.GetWholePart() method and it's a standalone issue in the library.

Expected Behavior
GetWholePart should work regardless of culture

Actual Behavior
Depending on the device culture it will return an incorrect value which may cause further issues down the line.

Steps To Reproduce
Set your device culture to Netherlands (one of the many countries which use , for decimals rather than .) and try to get the whole part or rounding a BigDecimal value, it should throw an exception due to it now using , rather than .

Screenshots
N/A

Additional context/Comments/Notes/Rants
I've installed the package into my Godot's .sln project via NuGet, version used: 2023.1000.4.35

Parse(Double input) fails , if CurrentCulture has NumberFormat with 'comma' instead of 'dot'

Hello,

BigDecimal Parse(Double input) => Parse(input.ToString(CultureInfo.CurrentCulture)); uses CurrentCulture to convert double into string, while next step uses BigDecimalNumberFormatInfo, which is InvariantCulture: public static BigDecimal Parse(String input) { return Parse(input, BigDecimalNumberFormatInfo); }

So, If CurrentCulture's NumberFormat is not similar to InvarantCulture, Parse + all releated tests will fail.
Example: new CultureInfo("ru-RU") has 'comma' for decimal point.

Add support for rounding value

Hi, thank you for this awesome library! I'd like to have this feature in your library.

Proposal/Summary
The rounding feature (up/down) is not supported by library

Rationale
It will all to round the value same way as Math.Round

Subtraction having issues.

Firstly, I want to say this is an excellent library and does exactly what I need. And it is much faster than other implementations I have looked at.

Description
Depending on the number of decimal places present in two BigDecimal numbers, subtraction will fail. I took several screenshots of both the code and local watches with similar numbers but with different amount of decimals. Sometimes subtraction would work and sometimes it wouldn't.

I have not seen any issues with multiplication, division, or addition. I have not tried testing any other functions as I currently don't need them.

Error/Exception Message
Was an exception thrown? If so, please paste the full exception message here. Please include the full stacktrace if you have it. If you don't have a stacktrace, but you think you can reproduce the bug, please run the application in debug mode and trigger the exception again. A full stacktrace should be available to debug builds, but probably not for release builds.
Otherwise, just give us a much of the error message or exception message as you can here. Please provide the error message in full and verbatim.

Expected Behavior
Receive correct result, consistently.

Actual Behavior
Expected behaviour was intermittent, with failures easy to reproduce.

Steps To Reproduce
Should be clear in the screenshots.

Screenshots
https://i.imgur.com/wtVicag.png
https://i.imgur.com/pFWQduO.png
https://i.imgur.com/qSsLwdP.png
https://imgur.com/2bNXrwC.png
https://i.imgur.com/wT1L0gv.png
https://i.imgur.com/ulCRTwR.png
https://i.imgur.com/IlcsV9W.png
https://i.imgur.com/2qt9hst.png

Additional context/Comments/Notes/Rants
Windows 10 x64 21H2 Build 19044.1645
Visual Studio Community 2022 17.1.4

Exe net6.0 disable enable x64

I have a collection of .Net SDKs and Runtimes installed from using multiple versions of Visual Studio over the years. I will try cleaning them up and see if that solves the issue.

C:\Windows\system32>dotnet --info
.NET SDK (reflecting any global.json):
Version: 7.0.100-preview.3.22179.4
Commit: c48f2c30ee

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100-preview.3.22179.4\

Host (useful for support):
Version: 7.0.0-preview.3.22175.4
Commit: 162f83657c

.NET SDKs installed:
6.0.104 [C:\Program Files\dotnet\sdk]
6.0.300-preview.22204.3 [C:\Program Files\dotnet\sdk]
7.0.100-preview.3.22179.4 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-preview.3.22178.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-preview.3.22175.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.23 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-preview.3.22177.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

I will also try downloading BigDecimal code and see if the unit tests pass on my machine. Will post update when completed.

Propose a way to store BigDecimal in SQL tables

Frequently it is required to store BigDecimal in database with ability to use it in matching and ORDER BY clauses. I've implemented next approach in my project:

I split BigDecimal into Whole, Fractional parts with total size 32 bytes:

  • 2 bytes: 1 bit - (1 if sign > 0) and 15 bits - biased exponent
  • 14 bytes: hi -> lo, aligned to right (not() if sign < 0)
  • 1 byte: qty of fraction leading decimal zeroes (not() if sign > 0)..ie.. 11.000123 -> 3 leading zeroes;
  • 13 bytes: hi -> lo, aligned to left (not() if sign < 0)
  • 1 byte: qty of used bytes in whole part
  • 1 byte: qty of used bytes in fraction part

example:

11,123 -> 1100000000000000 ...00000001011 11111111 01111011000... 00000001 00000001
11,125 -> 1100000000000000 ...00000001011 11111111 01111101000... 00000001 00000001
12,123 -> 1100000000000000 ...00000001100 11111111 01111011000... 00000001 00000001
12,125 -> 1100000000000000 ...00000001100 11111111 01111101000... 00000001 00000001
-11,123 -> 0100000000000000 ...11111110100 00000000 10000100111... 00000001 00000001
-11,125 -> 0100000000000000 ...11111110100 00000000 10000010111... 00000001 00000001
-12,123 -> 0100000000000000 ...11111110011 00000000 10000100111... 00000001 00000001
-12,125 -> 0100000000000000 ...11111110011 00000000 10000010111... 00000001 00000001

This approach allows to store BigDecimal with 34 digits for whole part and 32 digits for fractional.

int conversionBytesForSqlBlob = 32;
int conversionBytesForMainPart = conversionBytesForSqlBlob / 2;
int conversionBytesForExponent = 2;
int conversionBytesForInteger = conversionBytesForMainPart - conversionBytesForExponent;
int conversionBytesForFractionPart = conversionBytesForSqlBlob - conversionBytesForMainPart - 2;
int conversionBytesForLeadingZeroes = 1;
int conversionBytesForFraction = conversionBytesForFractionPart - conversionBytesForLeadingZeroes;
int conversionBitsForExponent = conversionBytesForExponent * 8 - 1;
int conversionBiasedMaxValue = 32768; //(int)Math.Pow(2, conversionBitsForExponent);
int conversionBiasedMidPoint = conversionBiasedMaxValue / 2;
int conversionMaxExponent = conversionBiasedMaxValue - conversionBiasedMidPoint;
int conversionMinExponent = -conversionBiasedMidPoint;
int conversionMaxDigitsInteger = 34;// (int)(conversionBytesForInteger * 8 * Math.Log10(2)) + 1;
int conversionMaxDigitsFraction = 32;// (int)(conversionBytesForFraction * 8 * Math.Log10(2)) + 1;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.