Results 1 to 10 of 10

Thread: Reciprocals

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    how do i find a Reciprocal through Visual Basic?


    thanks in advance
    NXSupport - Your one-stop source for computer help

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    what do you mean by a reciprocal?

    give us an example

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    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.

  4. #4
    Guest
    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    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.

  7. #7
    Addicted Member overhill's Avatar
    Join Date
    Mar 2000
    Location
    KS, United States
    Posts
    181

    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!

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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)

  9. #9
    Addicted Member overhill's Avatar
    Join Date
    Mar 2000
    Location
    KS, United States
    Posts
    181

    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.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    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
  •  



Click Here to Expand Forum to Full Width