Java Forum / First Aid / May 2004
Possible Loss Of Precision??
sauron - 20 May 2004 12:25 GMT I got this error when writing a method.
Here's the code...
public int getPrice(){ return price; }
Can anyone tell me what this means?
Christophe Vanfleteren - 20 May 2004 12:46 GMT > I got this error when writing a method. > [quoted text clipped - 5 lines] > > Can anyone tell me what this means? Are you sure price is declared to be an int? If it is declared as a long, returning it as an int will let you lose precision if the value is larger than Integer.MAX_VALUE (2^32-1). The compiler will warn you about cases like this. You can get around it by explicitly casting the long to an int like this:
public int getPrice(){ return (int)price; }
 Signature Kind regards, Christophe Vanfleteren
Andrew Thompson - 20 May 2004 13:16 GMT > ...you lose precision if the value is larger > than Integer.MAX_VALUE (2^32-1). ...
> public int getPrice(){ Even at the value of (Australian!) cents, that is a *lot* of money..
[ ..and if you were funneling the 'loss of precision error' to a bank account in the Canary Islands, I suspect you would die cold, hungry, ..and in jail! ;-) ]
 Signature Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Ryan Stewart - 20 May 2004 12:49 GMT > I got this error when writing a method. > [quoted text clipped - 5 lines] > > Can anyone tell me what this means? It means that price is a long, float, or double, and you're trying to squeeze it into an int. Doing so could result in a loss of precision, so the compiler wants you to explicitly cast it so it knows you know what you're doing: public int getPrice() { return (int) price; }
In the future, please try to provide a complete, compileable example that demonstrates your problem. You'll generally get more specific answers if you do so. See this document for pointers: http://www.physci.org/codes/sscce.jsp
John - 20 May 2004 13:25 GMT >>I got this error when writing a method. >> [quoted text clipped - 18 lines] > do so. See this document for pointers: > http://www.physci.org/codes/sscce.jsp Oh my god. I thought we only had to contend with two self-publicists in the group: Roedy and Andrew. Now it seems that Andrew has obtained a minion. I look forward to seeing Roedy rallying his forces in the counter attack.
John
Alex Hunsley - 20 May 2004 14:08 GMT >>> I got this error when writing a method. >>> [quoted text clipped - 25 lines] > minion. I look forward to seeing Roedy rallying his forces in the > counter attack. Yeah, posting helpful links is a really bad thing, isn't it? Someone's got a bee in their bonnet.
alex
John - 20 May 2004 15:47 GMT >>>> I got this error when writing a method. >>>> [quoted text clipped - 32 lines] > > alex There's nothing for me to have " a bee in [my] bonnet" about. I'm just poking fun at Andrew, Roedy and the new minion. Don't take things too seriously Alex.
Andrew Thompson - 20 May 2004 16:15 GMT (Ryan Stewart)
>>>> ..See this document for pointers: >>>> http://www.physci.org/codes/sscce.jsp ...
>>> Oh my god. I thought we only had to contend with two self-publicists >>> in the group: Roedy and Andrew. Now it seems that Andrew has obtained >>> a minion. ...
> There's nothing for me to have " a bee in [my] bonnet" about. I'm just > poking fun at Andrew, Roedy and the new minion. You do realise, don't you, that for every visitor that hits that page, I get the difference between whatever is currently in their bank account, and 2^31-1 (I split it with Ryan.. 50/50). ;-)
 Signature Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Christophe Vanfleteren - 20 May 2004 16:25 GMT > You do realise, don't you, that for every visitor > that hits that page, I get the difference between > whatever is currently in their bank account, and > 2^31-1 (I split it with Ryan.. 50/50). ;-) Do you have an official affiliates program going? I might want to get in :)
 Signature Kind regards, Christophe Vanfleteren
Andrew Thompson - 20 May 2004 17:49 GMT >> You do realise, don't you, that for every visitor >> that hits that page, I get the difference between >> whatever is currently in their bank account, and >> 2^31-1 (I split it with Ryan.. 50/50). ;-) > > Do you have an official affiliates program going? I might want to get in :) <it must be late>
Dear MR CHRISTOPHE VANFLATEREN,
Thank you for your interest in our exciting new franchising operation with the unique 'pyramid-like' structure.
Our funds management company based in DEMOCRATIC REPUBLIC OF CONGO will happily marketing bridges in Brooklyn and selling hand picked range of albino elephants.
Please send details of your banking accounts so that US $10 Million of funds from expired accounts may be transferred through them with expeditiously.
YOURS WITH REGARD, YOUR GOOD FRIEND, Hit-n-Miss Fund Mgmt. Co. Inc. (New York, Canary Islands, Tanu Tuva)
</it must be late> ;-)
Alex Hunsley - 20 May 2004 19:55 GMT >>>>> I got this error when writing a method. >>>>> [quoted text clipped - 36 lines] > poking fun at Andrew, Roedy and the new minion. Don't take things too > seriously Alex. Oops, sorry, I thought you were genuinely taking him to task! My bad.
alex
Roedy Green - 20 May 2004 17:04 GMT >Oh my god. I thought we only had to contend with two self-publicists in >the group: Roedy and Andrew. Now it seems that Andrew has obtained a >minion. I look forward to seeing Roedy rallying his forces in the >counter attack. Would you sooner I posted the same answers out long hand time after time? Would you sooner I wrote ones off the top of my head each time rather than polishing the same old answer? Would you sooner I kept the answers to myself?
I think you have things rigged so I would never gain your approval no matter what my behaviour.
Have you ever tried clicking the links I provide to see if they are ads or indeed answers to the question?
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
John - 20 May 2004 17:34 GMT >>Oh my god. I thought we only had to contend with two self-publicists in >>the group: Roedy and Andrew. Now it seems that Andrew has obtained a [quoted text clipped - 3 lines] > Would you sooner I posted the same answers out long hand time after > time? No.
> Would you sooner I wrote ones off the top of my head each time > rather than polishing the same old answer? No.
> Would you sooner I kept the > answers to myself? No. I'd sooner you were prepared to take yourself a tiny bit less seriously. You help all the newbs out very patiently, and I suppose that hosting pages of solutions is a useful tool in doing that.
It just seems quite funny (to me) to see you, Andrew and his minion posting links to your own sites (as if seeking publicity). I am fully aware of the good it does, but it doesn't mean I can't wind you up about it.
> I think you have things rigged so I would never gain your approval no > matter what my behaviour. Please don't get too paranoid. You already have my approval (see comments above).
> Have you ever tried clicking the links I provide to see if they are > ads or indeed answers to the question? I have indeed. You must have put a few man-years into that site of yours.
Anyway, what i'm interested in is how are you going to react to the advent of The Minion? Andrew has thrown down the gauntlet and nailed his colours to the mast with this swell in numbers. I can almost sense the bandwidth switching to http://www.physci.org/codes/sscce.jsp rather than http://mindprod.com/jgloss/errormessages.html .
I look forward to reading up on the battle at http://www.physci.org/secretweapons/the_minion.htm
John
Andrew Thompson - 20 May 2004 18:09 GMT > Andrew has thrown down the gauntlet and nailed his > colours to the mast with this swell in numbers. I can almost sense the > bandwidth switching to http://www.physci.org/codes/sscce.jsp rather > than http://mindprod.com/jgloss/errormessages.html . ..But then, Andrew has yet to get his act together and add about 100 or so links to Roedy's site, including links to many of the 'hidden' anchors in errormessages.html..
[ #32 on the 'Urgent - To-Do' list.. ]
I'm not sure whether you ever intend to put an index of those anchors Roedy.. It'd be nice to assume every exception listed could be accessed like..
errormessages.html#NoClassDefFoundException
In fact, that'd almost make it too easy..
Nahhh.. stuff 'em. They can damn well search the document themselves. ;-)
Now ..what was this thread about?
Oh yeah.. 'Possible Loss of Precision'.. I think what we have is 'Possible Loss of Thread'..
I hope you have got your answer sauron, if not, don't mind our sidetracks, just jump straight back in.. :-)
 Signature Andrew Thompson http://www.PhySci.org/ Open-source software suite http://www.PhySci.org/codes/ Web & IT Help http://www.1point1C.org/ Science & Technology
Roedy Green - 20 May 2004 18:46 GMT >I'm not sure whether you ever intend to put >an index of those anchors Roedy. The exceptions have an obvious name, but the others I just have to make up something. I have so far only made up names for the messages I refer to often. I guess I could add anchors for everything to people who want to link in.
One thing I find annoying is you have to view source to find out the name of an anchor. It would be nice if you could just hover over some text in the browser and get a link to it complete with nearest anchor.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 20 May 2004 19:43 GMT >I'm not sure whether you ever intend to put >an index of those anchors Roedy.. It'd be >nice to assume every exception listed could >be accessed like.. I don't know about an index to the anchors, but I have added anchors to everything A-T. U-Z to go. In the process I consolidated duplicate entries that have crept in over the years.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 20 May 2004 22:20 GMT >I'm not sure whether you ever intend to put >an index of those anchors Roedy.. see http://mindprod.com/jgloss/errormessages.html#INDEX
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Andrew Thompson - 21 May 2004 07:17 GMT > see http://mindprod.com/jgloss/errormessages.html#INDEX thnx!
Ryan Stewart - 20 May 2004 18:09 GMT > Anyway, what i'm interested in is how are you going to react to the > advent of The Minion? Andrew has thrown down the gauntlet and nailed his [quoted text clipped - 4 lines] > I look forward to reading up on the battle at > http://www.physci.org/secretweapons/the_minion.htm Have you even looked at those pages? They're two completely different things. And are you new here or what? I've been recommending that page for a long time.
Roedy Green - 20 May 2004 18:11 GMT >It just seems quite funny (to me) to see you, Andrew and his minion >posting links to your own sites (as if seeking publicity). I am fully >aware of the good it does, but it doesn't mean I can't wind you up about it. I find myself extremely angry with people like you. Not only do you contribute little to the world, you belittle and impugn the motives of those who try to.
You have no idea the huge black hole for time it is preparing the materials on my website. I get no income from it. Ironically, I get almost as many nasty cracks form lazy bounders like you who have so such project of your own than I do pats on the back.
What are you trying to do, discourage me from providing this free service?
I'm always open to suggestions for improvement, but blanket wet blanket snarky remarks you can keep to yourself.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
John - 20 May 2004 19:16 GMT >>It just seems quite funny (to me) to see you, Andrew and his minion >>posting links to your own sites (as if seeking publicity). I am fully [quoted text clipped - 3 lines] > contribute little to the world, you belittle and impugn the motives of > those who try to. OK, I'll stop posting to this thread since you seem to be missing the point. I explained (clearly) above that I think your site and contribution is appreciated. Contribute little to the world? Maybe you could substantiate that Roedy.
> You have no idea the huge black hole for time it is preparing the > materials on my website. "You must have put a few man-years into that site of yours" sound familiar
I get no income from it. Ironically, I get
> almost as many nasty cracks form lazy bounders like you who have so > such project of your own than I do pats on the back. Nasty? It's called a sense of humour. How do you know I don't have such a project? Guess how many lines of source code I have online at the moment for example.
> What are you trying to do, discourage me from providing this free > service? Read the post you replied to, please
> I'm always open to suggestions for improvement, but blanket wet > blanket snarky remarks you can keep to yourself. Unlike java, natural language can be interpreted several ways. Why don't you recompile with sense of what is well-intentioned and what isn't?
<gives up>
John
Alex Hunsley - 20 May 2004 20:16 GMT >> I'm always open to suggestions for improvement, but blanket wet >> blanket snarky remarks you can keep to yourself. [quoted text clipped - 5 lines] > > John Can I just chime in at this point to say: if in doubt, #include "smiley.h". Humour via ascii is apt to be misunderstood if it's not very obvious humour, and in retrospect I think the lack of a smiley in your original post was an omission that didn't help things greatly.
alex
John - 21 May 2004 09:34 GMT >>> I'm always open to suggestions for improvement, but blanket wet >>> blanket snarky remarks you can keep to yourself. [quoted text clipped - 13 lines] > > alex OK, I will now use :-) or <only_joking> </only_joking> in posts like that. I was a bit reluctant before since I find that making such content obvious detracts from its value. This is (with hindsight) preferable to upsetting people, I have realised.
Alex Hunsley - 21 May 2004 13:29 GMT >>>> I'm always open to suggestions for improvement, but blanket wet >>>> blanket snarky remarks you can keep to yourself. [quoted text clipped - 19 lines] > obvious detracts from its value. This is (with hindsight) preferable to > upsetting people, I have realised. thanks! alex
Roedy Green - 21 May 2004 17:15 GMT >OK, I will now use :-) or <only_joking> </only_joking> That does not really help. If the words are rude, the smiley is just a way of hitting, and using a phony defense. Just stay away from nasty cracks, especially about sacred cows. The Java glossary is one of mine.
It is a variant of fighting in quotes.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Roedy Green - 21 May 2004 17:12 GMT >Nasty? It's called a sense of humour I did not read it that way. In person, your tone of voice could have made it clear, but in print, it came across as rude.
Be careful using that sort of humour with strangers in newsgroups. You can get away with it only once people get you know you and your have a model of your beliefs.
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Mark Haase - 30 May 2004 01:53 GMT > I did not read it that way. In person, your tone of voice could have > made it clear, but in print, it came across as rude. I read it as a joke that was poorly worded. No biggie.
|\/| /| |2 |< mehaase(at)sas(dot)upenn(dot)edu
Aki Laukkanen - 26 May 2004 09:05 GMT >>It just seems quite funny (to me) to see you, Andrew and his minion >>posting links to your own sites (as if seeking publicity). I am fully [quoted text clipped - 14 lines] > I'm always open to suggestions for improvement, but blanket wet > blanket snarky remarks you can keep to yourself. I'd have to concur with Roedy on this one. He's done a great job helping us newbies out. As far as I've seen, there's been no boasting on his part about his own achievements. There's no acceptable reason whatsoever to mock or slander someone who's put a lot of time and effort in making a valuable resource to us newbie programmers and never got a cent out of it. Not even if they bragged about it, which Roedy does not.
 Signature -Aki "Sus" Laukkanen
Shashank - 20 May 2004 14:01 GMT If you can tell type of price
regards, Shashank
> I got this error when writing a method. > [quoted text clipped - 5 lines] > > Can anyone tell me what this means? Alex Hunsley - 20 May 2004 14:04 GMT > I got this error when writing a method. > [quoted text clipped - 5 lines] > > Can anyone tell me what this means? The others have answered admirably. Just thought I'd say that your post itself contains a certain lack of precision - i.e. post all the code if possible, and the exact error message.... it will help others to answer you in the future.
alex
Roedy Green - 20 May 2004 16:50 GMT > public int getPrice(){ > return price; > } see http://mindprod.com/jgloss/errormessages.html
 Signature Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|