overflowexception

Why dividing int.MinValue by -1 threw OverflowException in unchecked context?

风流意气都作罢 提交于 2020-01-19 06:55:02
问题 int y = -2147483648; int z = unchecked(y / -1); The second line causes an OverflowException . Shouldn't unchecked prevent this? For example: int y = -2147483648; int z = unchecked(y * 2); doesn't cause an exception. 回答1: This is not an exception that the C# compiler or the jitter have any control over. It is specific to Intel/AMD processors, the CPU generates a #DE trap (Divide Error) when the IDIV instruction fails. The operating system handles the processor trap and reflects it back into

Why dividing int.MinValue by -1 threw OverflowException in unchecked context?

好久不见. 提交于 2020-01-19 06:53:29
问题 int y = -2147483648; int z = unchecked(y / -1); The second line causes an OverflowException . Shouldn't unchecked prevent this? For example: int y = -2147483648; int z = unchecked(y * 2); doesn't cause an exception. 回答1: This is not an exception that the C# compiler or the jitter have any control over. It is specific to Intel/AMD processors, the CPU generates a #DE trap (Divide Error) when the IDIV instruction fails. The operating system handles the processor trap and reflects it back into

Oracle number to C# decimal

给你一囗甜甜゛ 提交于 2019-12-29 01:33:11
问题 I know there are several threads and posts regarding this issue in the internet and I've read them (not every article, I have to admit) but none of them did fully satisfy me. My situation: I'm using ODP.net (dll version 2.111.6.0) to access the Oracle DB (version 10 + 11) and a DataReader to retrieve the data (.NET 3.5, C#). Using this code results in a ' System.OverflowException (Arithmetic operation resulted in an overflow.) ' decimal.TryParse(oraReader.GetOracleDecimal(0).Value.ToString(),

Determine if integer overflow is over or under bounds

孤人 提交于 2019-12-24 13:15:22
问题 Using C#, I have a few custom classes where I need to be able to detect integer overflows and return a default minimum or maximum value depending on if the overflow was due to the result being over the maximum value or under the minimum value. I can't seem to find a suggestion on how to detect the "type" of overflow that occurs anywhere. The classes are divided between two general types: ones that use signed values, and ones that use unsigned values. As an example, here is one of the classes

How can I stop OverflowException being thrown on integer division?

十年热恋 提交于 2019-12-24 00:07:05
问题 I am getting OverflowException 's thrown at me when I don't want them (or so I think). I am performing some odd calculations where I expect the values to overflow, discarding overflowed bits. It seems I can't get this to work properly though. Basically this is one pair of i and j which happens as I iterate over huge sets (int.MinValue to int.MaxValue). // i and j are ints // i is -2147483648 // j is -1 var x = i / j; // I also tried using unchecked keyword, but it doesn't help var x =

Why doesn't this produce an overflow exception?

与世无争的帅哥 提交于 2019-12-21 17:34:42
问题 I was testing something out using LinqPad and was surprised that the following code did not produce an exception: ulong lSmallValue = 5; ulong lBigValue = 10; ulong lDifference = lSmallValue - lBigValue; Console.WriteLine(lDifference); Console.WriteLine((long)lDifference); This produces the following output: 18446744073709551611 -5 Fortunately, I was hoping for this behavior, but I was under the assumption that this would cause an OverflowException to be thrown. From System.OverflowException:

OverflowException with Delimon Directory.Exists

梦想与她 提交于 2019-12-12 06:25:02
问题 I have a really strange error, with Delimon.Io library, I got an OverflowException when I call a Directory.Exists for an existing directory, ie. Delimon.Win32.IO.Directory.Exists(@"c:\temp") The error occours only if I issue the call in a specific service, no error if I run the same code in unit testing project. What could be the project settings that makes this simple call fail? (Clearly calling a System.IO.Directory.Exists("c:\\temp") correctly returns true . 来源: https://stackoverflow.com

How can I determine which element is causing an overflow?

筅森魡賤 提交于 2019-12-12 04:57:15
问题 I've got this code: String testData = File.ReadAllText("siteQueryTest.txt"); XDocument xmlDoc = XDocument.Parse(testData); List<SiteQuery> sitequeries = (from sitequery in xmlDoc.Descendants("SiteQuery") select new SiteQuery { Id = Convert.ToInt32(sitequery.Element("Id").Value), UPCPackSize = Convert.ToInt32(sitequery.Element("UPCPackSize").Value), UPC_Code = sitequery.Element("UPC_Code").Value, crvId = sitequery.Element("crvId").Value, dept = Convert.ToInt32(sitequery.Element("dept").Value),

java.lang.StackOverflowError: null JsonWriter.writeDeferredName but not using Json?

主宰稳场 提交于 2019-12-11 18:27:40
问题 I know the title isn't the best, but the error is not clear at all to me. The error I have is this: 019-04-15 14:28:45.270 ERROR 12644 --- [nio-9090-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause java.lang.StackOverflowError: null at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401) ~[gson

array creation expressions and long dimension lengths

孤人 提交于 2019-12-10 19:41:15
问题 I was just reading the C# specification and the part on array creation expressions. In the specification it says: array-creation-expression: new non-array-type [ expression-list ] rank-specifiersopt array-initializeropt new array-type array-initializer new rank-specifier array-initializer [snip] The dimension length expressions of the expression-list are evaluated in order, from left to right. Following evaluation of each expression, an implicit conversion (§6.1) to one of the following types