Casting int to double issue in JRockit - casting

I have a bea weblogic 8.1 sp5 server running on a JRockit instance with the following java version:
*java -version
java version "1.4.2_10"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_10-b03)
BEA JRockit(R) (build R26.3.0-32-58710-1.4.2_10-20060308-2022-linux-ia64, )*
I face an issue when the following code is executed:
int debt = 27003; //amount in cents;
System.out.println(((double) debt18 / 100)); //amount in euro
The printed result is 270.03000000000003
I am sure that this is a virtual machine error since it is observable on this particular jrockit machine.
Do you happen to face a similar problem in the past?
Can you please tell me a less error-prone way to pass the wanted value to a double variable,preferably using standard java libraries?

I know that this is pretty old but i have an answer and maybe it will help somebody in the future. I used the DecimalFormat object to keep only the digits that were useful to me. Only one decimal was needed and it was always correct, even when the error appeared so this is OK for me.
The code is the following:
String pattern = "##0.0#";
DecimalFormatSymbols separator = new DecimalFormatSymbols();
separator.setDecimalSeparator('.');
DecimalFormat decimalFormatter = new DecimalFormat(pattern, separator);
int debt = 27003; //amount in cents;
System.out.println(decimalFormatter.format(((double) debt18 / 100)));

Related

Why cant I use a Character length more than 65535 RPGIV

I red the following article and it seems like I should be able to define a variable of type varying that's size limit will be 16mb instead of 65535 characters.
http://www.mcpressonline.com/programming/rpg/v6r1-rpg-enhancements.html
This forum post suggests that it is posible to do this in V6.1.
http://www.code400.com/forum/forum/iseries-programming-languages/rpg-rpgle/11426-character-string-max-length
D BigVarying S a Len(25000000) Varying(4)
When I try to implement this I get the following errors and it seems like I cannot use Len(25000000) Varying(4)
Maybe I don't understand what exactly is meant by V6.1 but I checked on the Green screen using the command DSPSFWRSC and get the following Release V6R1..
I also checked by using I systems navigator and I checked the servers properties and it is : i5/OS version Version 6 Release 1 Modification 0.
The IDE I use to compile is IBM Websphere development studio
Version: 7.0.0
Build id: 20070202_0030
Trying to compile a RPGLE function.
Am I checking the correct version or is there a RPG version and how do you check it.
can you please help me out of my confusion.
V6.1 is your operating system version and you can refer to the V6.1 ILE RPG Language Reference here to see if it's possible. I think what you're looking for is on page 185.
I've just tested this in 7.2 and I am not getting the same errors.
D BigVarying S a Len(25000000) Varying(4)
RNF0501E Length of character item exceeds 16773104; length defaults to 16773104.
RNF0231E Length of varying length character item exceeds 16773100; length defaults to 16773100.
//Dcl-S BigVarying Varchar(25000000);
BigVarying = 'Hello world';
Return;
So, as the (duplicate) error mentions
Length of character item exceeds 16773104; length defaults to 16773104.
If you'd like a bigger length you'll need to update to a newer version of IBM i - but the max length is also 16773104, meaning 25000000 is invalid.
While RPGLE supports 16MB variables from 6.1 forward and you are on 6.1..
You have two problems:
25000000 (23.8MB) is bigger than 16773104 (~16MB)
Websphere Development Studio v7 (WDSc) is older than IBM i 6.1 (your build date is 2007, the article you're referencing came out in 2008). So your IDE doesn't recognize the new keywords and new max size.
Problem #2 isn't a deal breaker, you can simply ignore the errors in the IDE and compile on ther server successfully. If you were using the green screen editor SEU, you'd have to do the same as IBM stopped enhancing SEU at 6.1.

LoadFrame (MFC) failing only in Australia

Our team has a bug that has stumped us.
The following code returns false:
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
{
AfxMessageBox(GetStr(IDS_MAINFRM_FAIL_TO_LOAD));
ASSERT(FALSE);
return FALSE;
}
We're compiling using VS2010, and we do have the RogueWave Stingray component installed. The CMainFrame is a CBCGPMDIFrameWnd which is based off of a CMDIFrameWnd and made by BCGSoft.
We have our software running on about 100 machines globally with no issues. Its running on Windows 7-10 x86 & x64. It always worked, until this week. A small group of people in Mildura, Australia have reported an issue. For all of them, running WIN7x86Enterprise and Win10x64Home, the code snippet above returns false. I personally inspected one of their machines (Win10x64Home) and everything seems to be in order.
I've tried deleting the RES and APS files for the project. That didn't help.
Does anyone know what the problem might be? I'm open to educated guesses.
Thanks in advance!
PS: New Info:
It looks like its a time issue. On the computer, everything UTC+ fails, and UTC0 & UTC- pass. We aren't sure why. Any help would be appreciated. Thanks!
We were doing TimeDate calcs on an elapsed timestamp using the epoch as a starting point. MFC doesn't allow dates before the epoch, so all UTC+ failed the date creation. This bug has been fixed. Thank you to everyone.
Here is the code that was causing the issue (fixed). We added one day on for everything to work. CTime::CTime(1970,1,1,0,0,0) w/ UTC+ ,making it before 1/1/1970 in London, fails.
Thanks!
CTime t1 = CTime::CTime(yearInt,monthInt,dayInt,0,0,0);
CTime t2 = CTime::CTime(1970,1,2,0,0,0);
CTimeSpan timeSpan = t1-t2;
versionDate = timeSpan.GetDays() + 1;

c++ local variable gets overwritten (but only on some notebook)

I am facing some strange behaviour appearing only on some notebook.
I am developing in c++ using msvc 2012 and the qt framework.
I will try to sum up the problem and i am hoping that someone has any idea what the problem could be or what i could try to find out..
Generally it's the following problem:
void myclass::foo()
{
const double value1 = 100.0;
double value2;
value2 = some_function_returning_double();
if(value1 > value2)
{
//__ do something
}
}
The problem is that the condition fails as the local variable gets overwritten.
If I do some debug output i can see that variable value1 is not 100.0 anymore but some random value .. so that the comparison randomly fails ..
One thing i figured out is that everything just works fine if i don't use local variables. If i set up value1 and value2 as member variables of my class everything works without problems, but that can't be the solution.
Now the strange thing is that this error does only occur on some notebook (some mobile i5 cpu).
On my machine (i5) and on many other notebooks (even other mobile i5) everything just works fine.
I know that you won't be able to solve my problem with this little information i can offer here, but maybe some of you has any hint what the problem could be and what i could try to solve this.
Many thanks in advance.
In visual studio 2012, add a data breakpoint (debug->new breakpoint->new data breakpoint) on the address of the variable that gets overwritten.
First, break at the start of the function.
Then set the data breakpoint: just type &value1 in the "New breakpoint` the input box.
Then it should break just after the value has been modified, and you should see the culprit.
Data breakpoints are a very powerful tool, that helped me found nasty bugs very quickly.

Java 7: Cannot cast from Object to int etc

I'm having a problem running someones code in Eclipse 3.6 (Helios). The code is written with OpenJDK 7. I'm running Windows 7 and I had to install Java 7 for it. I was using Java 6 before. I get 2 kinds of errors running the code:
"Cannot cast from Object to int" (also: double, long, boolean)
"Cannot instantiate the type HashSet<?>"
I read casts like "(int) obj" are only possible in Java 7. In Java 6 it has to be "(Integer) obj" instead. But I set the "JRE System Library" to JRE7 and I still get that error. Is it still somehow using JRE6?
The second problem is caused by "Set set; set = new HashSet<>()". The problem is gone if you replace HashSet<>() with HashSet<String>(). Is this another Java 7 change? And why is it not working with my JRE7? Is my Eclipse too old and only able to run JRE6?
Thanks in advance,
Torben
You're describing new features in the Java 7 compiler.
You need to use the Java 7 compiler, with any version of the JRE.

Incomplete highlight in c++-mode with Emacs

I work with C++ in emacs, and it works perfect, except for a detail when highlighting the code. Whenever I write a function with more than one argument (sometimes, even with just one), it does not recognice the function as a function, for instance, in:
double Gamma(double x, double mean, double gamma){
//some code
}
Gamma is not highlighted like a function, but as plain text, while in #define square(x) x*x, square is properly highlighted, as well in
complex<double> magphase2c(double mag, double phase){
// some code
}
where magphace2c is highlighted as a function.
The same behaviour occurs when I have, for instance,
TF1 *fitBWResult = new TF1("fitBWResult", BreitWigner, ResMassMin, ResMassMax, 3);
// versus
double Mass = 0.776132;
where fitBWResult is not recognized as a variable, but Mass is. This last problem only happens when I use pointers.
I'm using Emacs 23.4.1, I don't know the version of cc-mode, but I'm running an up to date installation of Debian testing (wheezy).
Thanks in advance!
I think this question shouldn't be left without an answer, and since I solved it thanks to the idea of user noisecapella, I post the solution I found:
Debian Wheezy, at the time, uses cc-mode 5.31.8 with Emacs 23.4.1, and this version of cc-mode is the one with the problem. The solution is install the newer version (maybe an old one may do the job, also) of the package, from their homepage. Particularly, I solved the issue installing version 5.32.3, the newer at the time being.