0

Hey,
I'm a student, doing VB at college. I've been trying to make a program to compute Pi, and am making good progress, I think I know what to do. However, part of the algorithm requires me to cube a number. The way I'm doing it is having stored the number in an array, with each cell in the array 1 digit. I've made sub procedures to add/subtract 2 arrays, and multiply/divide an array by a number.
This code multiplies mul1() by a single number mul2

Sub mul(ByRef mul1() As Byte, ByRef mul2 As Byte)
        Dim hold, carry, temp(digits + 1) As Byte
        For a = digits + 1 To 0 Step -1
            If a > 0 Then
                hold = mul1(a - 1) * mul2 + carry
            End If
            carry = hold \ 10
            temp(a) = hold Mod 10
        Next a
        For a = 0 To digits
            mul1(a) = temp(a)
        Next a
    End Sub

Notice I also want the result to be to the same precision as the numbers going in,
So 0.256*0.256 would give 0.065, because I would have only asked for 4 digits ('digits' variable) in that case. It's this that's giving me trouble.

Any advice appriciated :), cheers.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fereak
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.