Today I am facing to the issue in addition Double + 1.
Console.WriteLine(-1.09 + 1) - Returns 0,0900000000000001
Console.WriteLine(-1.05 + 1) - Returns 0,05
I was testing the range of double when it give me strange values and I have found that wrong is onlz interval -1.06 to -1.09.
Work with Visual studio 16.4.5, framework target 4.7.2.
Tried the console.writeline and also other tests with values in variables.
Is that bug or I do something wrong?
Thank you
Thanks to Peter Ksenak Will use CDec() function with more significant digits.
Who need to learn more about that can do it here
Related
Trying to create a small Visual Basic console application in visual studio here. I need to obtain a couple of consecutive characters from a string entered by the user. I know how to return one character from a string using the getchar( 'string name', 'where is char you want located') but am not aware on how to obtain several consecutive chars. If there's way to do something like: getchar(string, count, count + 1, count + 2) that'd be great to know. And i'm not very experienced with visual basic or any type of code at all so keeping it simple and understandable would really be appreciated.
Thanks.
I'm starting to code in, and learn, VB.NET. And so far, it's been smooth sailing.
Until I try to run the program.
What I've done is, in a language I know and understand, wrote a hangman game. And in C#, the code works perfectly. Once I got it to this finished point where I can say that there is nothing else I wish to change about it, I started hand-converting it to VB.NET.
So far, no problem. But I just finished converting it, and now I have hit my snag.
On the bottom of the window is a status bar, telling you which puzzle set you're in and which puzzle you're on. When selecting a puzzle, this line of code throws an error:
stsPuzzles.Text = "Puzzle: " + regionPuzzles + "/" + maxPuzzles
The error is:
Conversion from string "Puzzle" to type 'Double' is not valid.
Of course, the easy answer would be to take this mechanic out, but at least for testing purposes, I'd like it in there so I can make sure the right puzzles are in the right sets.
Is there a way I can fix this so my two integer variables can be in the string? Or is there a work around that I can at least use long enough for testing purposes for the rest of the testing process?
I'm hoping to find a way to fix this, as there are other places, such as displaying stats, that need to be able to do this.
The direct fix for your existing code is this:
stsPuzzles.Text = "Puzzle: " + CStr(regionPuzzles) + "/" + CStr(maxPuzzles)
or this:
stsPuzzles.Text = "Puzzle: " & regionPuzzles & "/" & maxPuzzles
In VB.Net, &, rather than +, is the concatenation operator. + will often still work, but it also has a tendency to think you wanted arithmetic when an operand is numeric.
But what I would really do in this case, is this:
stsPuzzles.Text = String.Format("Puzzle: {0}/{1}", regionPuzzles, maxPuzzles)
or with Visual Studio 2015 or later:
stsPuzzles.Text = $"Puzzle: {regionPuzzles}/{maxPuzzles}"
I have an application which contains the line below to assign a parsed XML value to a variant array.
V(2) = latNode.Text * 1
This works fine on my system (Windows 7, Excel 2010) but doesn't work on some other system or systems - and I've not been able to get a response from the user who reported the problem.
I've switched out the offending line for:
V(2) = CDbl(latNode.Text)
This still works on my system, but then I had no problem in the first place. The question is on what systems does the first approach fail and why, and will the second method always work? I'm sure I've used the "String * 1" trick elsewhere before and would like to know how concerned I should be about tracking down other occurrences.
Thanks.
Maybe it's related to thousands separator and decimal mark. Office VBA uses cultural settings even in CDbl, in my German Excel version, it's reversed compared to English, CDbl("123.4") is parsed to 1234, CDbl("123,4") to 123.4.
Val(x) will always parse the dot as decimal mark.
I am working with Wolfram Mathematica 8 and have the following problem. I have an optimization problem under certain constraints and want to have an analytical (symbolical solution). I am maximizing function piA. My input is:
piA[a_, WA1_, WA0_] =
a/(1 + a)*(X - (y*WA1 + 1)^(1/y)) - 1/(1 + a) ((y*WA0 + 1)^(1/y));
Maximize[{piA[a, WA1, WA0], WA0 >= -1/y, WA1 >= -1/y}, WA0]
What I get most of the times is:
Maximize[{-((1 + WA0 y)^((1/y))/(1 + a)) + (
a (X - (1 + WA1 y)^(1/y)))/(1 + a), WA0 >= -(1/y), WA1 >= -(1/y)},a]
Basically, the command does nothing, but outputs itself. Only once I have managed to get the proper output (too long to paste here). I have tested it with simpler functions and it works. Unfortunately, I cannot understand what causes the problem. It is not a syntax problem, since it has worked like that several times. Any help would be very much appreciated.
P.S. Just checked again and my input ALWAYS generates the wrong output. The time it generated the solution was when I accidentally set parameters X and y to certain numbers.
The most likely reason is that given the function and constraints, Mathematica doesn't know how to maximize your function with respect to WA0. Note you also have a free variables X and a in there, and it might not have enough information about the domain of X and a to be able to properly form a solution to your equation.
I've had instances where I tried feeding in some equations and constraints and Mathematica simply couldn't do anything with them because they were too general. This may be the case here as well. Is there a specific problem you're trying to solve, and is there any way you could give Mathematica more context?
I don't think this is a bug at all, but it's unfortunate that sometimes Mathematica will just spit back your input when it doesn't have any rules for solving what you gave it.
The usual reason these things happens seems to be when the expressions given are too general for Mathematica to handle, or when it it's faced with a set of expressions that are ill formed.
Just as an example, I tried passing in fractions into a function I wrote that specifically looked for rational expressions, thinking it would work. It turned out that it needed to handle both Rational[a, b] and Times[a, Power[b, -1]]. It could be the case that Mathematica is not expecting a constraint to be of the form GreaterEqual[a, b].
Mathematica returns an answer if you assign the variable a some value. Maybe you could build your strategy on that? In fact it does provide an answer if you assign a value to any of the variables.
( I would need more background of the problem to go from there... )
Hey everyone, I'm wondering how to evaluate an expression using the assert object. The idea is to check if a string is longer then what is minimally acceptable. For example, Assert.AreEqual(stringName.length, >5). I know this method doesn't work but the concept is what I'm trying to get across. Is there a way to test this? Thanks in advance for any input anyone can provide.
What testing framework are you using?
NUnit has Assert.Greater(stringName.length, 5)
For MS Test you could use Assert.IsTrue(stringName.length >5)