LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2004, 05:34 AM   #1
champ
Member
 
Registered: Jul 2002
Distribution: Slackware 10.0
Posts: 46

Rep: Reputation: 16
java + negative exponents


Hi

Im trying to implement a algorithm in java using BigInteger class.
The problem is that I have to use negative exponents, but that doesn't work.
I have a value V which i want to raise to the power of -1. The BigInteger class has a method pow() which I can use, but it will raise an exception if I use a neg. exp.

How can I solve this?
 
Old 08-08-2004, 06:39 AM   #2
max_sipos
Member
 
Registered: Jul 2004
Posts: 96

Rep: Reputation: 15
Umm, I don't know anything about the BigInteger class. But if it is an integer, raising it to the power of -1 is equivalent to dividing 1 by the number which is bound to be a decimal number, not an integer.. The best thing it would do was give you a 0 as a result...
 
Old 08-11-2004, 12:07 AM   #3
champ
Member
 
Registered: Jul 2002
Distribution: Slackware 10.0
Posts: 46

Original Poster
Rep: Reputation: 16
I found the solution....

I use modular inversion. B = A^-1. B is the modular multiplicative inverse of A. And BigInteger class has a method called modInverse().

Code:
  BigInteger b = a.modInverse(modulusUsedInAlgorithm)
Since im using modular, the fraction will be lost. So it can be represented as a Integer
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GIMP does not negative coordinates in a .eps leontini Linux - Software 1 12-18-2005 01:46 PM
printing negative value as positive hubabuba Programming 5 05-03-2005 12:41 PM
Negative display for X? unholy Linux - General 0 11-15-2003 08:42 AM
Bad vibes in Java - bytes turning negative MadCactus Programming 3 08-29-2003 06:15 PM
A negative article about linux Rutnut Linux - General 8 05-13-2002 12:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration