|
-
Oct 27th, 2000, 10:18 PM
#1
Thread Starter
Frenzied Member
how do i find a Reciprocal through Visual Basic?
thanks in advance
NXSupport - Your one-stop source for computer help
-
Oct 27th, 2000, 11:45 PM
#2
Lively Member
what do you mean by a reciprocal?
give us an example
-
Oct 28th, 2000, 01:36 AM
#3
Frenzied Member
1/X?
What is wrong with dividing one by the number?
Code:
Dim Number As Double
Dim Reciprocal As Double
Reciprocal = 1/Number
Does "reciprocal" mean something else to you?
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Oct 28th, 2000, 07:27 AM
#4
Dividing the number by one will only work for an integer. For example dividing 2/3 by one won't give you 3/2.
Just a quick thought,
Code:
Public Function MakeReciprocals(fraction As String) As String
Dim pos As Integer
Dim p1 As String
Dim p2 As String
pos = InStr(fraction, "/")
p1 = Mid(fraction, 1, Len(fraction) - pos)
p2 = Mid(fraction, pos + 1)
MakeReciprocals = p2 & "/" & p1
End Function
Sunny
-
Oct 28th, 2000, 09:35 AM
#5
Thread Starter
Frenzied Member
by a reciprocal i mean like this:
2/1 = 1/2
.25 = 4/1
3/2 = 2/3
etc.
and Sunnyl:
that code woun't always work like if its .25, it will not give 4/1 or 4
NXSupport - Your one-stop source for computer help
-
Oct 28th, 2000, 11:12 AM
#6
Frenzied Member
Divide into one.
Dividing by one results in doing nothing. Divide one by the number to get reciprocal.
If number is expressed as single or double, the code I previously posted will work.
If you have numerator and denominator of a fraction, turn fraction upside down. Numerator becomes denominator and vice versa,, resulting in reciprocal.
1/4 = .25 (.25 is reciprocal of 4).
1/.25 = 4 (4 is reciprocal of .25).
1/(4/3) = 3/4 (3/4 is reciprocal of 4/3, and vice versa)
I understood what you meant, but statements like "3/2 = 2/3" give mathematicians a queasy feeling.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Oct 29th, 2000, 05:41 PM
#7
Addicted Member
Reciprocal
Similar to Guv's way this way will also work. It is the same mathematical function, but one may be faster.
Take the number to the -1 power.
Example:
(0.25)^-1 = 4
Hope that this helps!
-
Oct 29th, 2000, 06:36 PM
#8
Frenzied Member
I don't wish to contradict overhill, but I will. x^-1 is very much slower than 1/x. the ^ operator is very slow (because of the way the FPU works, nothing to do with VB)
-
Oct 29th, 2000, 11:25 PM
#9
Addicted Member
Thanks Sam
Thanks for the comment Sam. I had a feeling that powers were probably slower, but you confirmed it. I just threw out my way of doing it when using a calculater. In that environment it is simpler just to take the number to the -1 power. Thanks.
-
Oct 29th, 2000, 11:51 PM
#10
Thread Starter
Frenzied Member
thanks to all for your help
NXSupport - Your one-stop source for computer help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|