FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
May 01, 1994

Temporary Object Management through Dual Classes

(Page 3 of 5)
May 1994/Temporary Object Management through Dual Classes/Listing 1

Listing 1 Vector function unit

Vector unit(const Vector& v)  // Unitize the input vector
{    Vector u(v.length());         // Create same size Vector
    int i;
    double sumsq = 0.0;
    for (i = 0; i < v.length; i++)  // Find sum of squares
        sumsq += v(i) * v(i);
    if (sumsq !=0.0)   // Avoid divide by zero problems
        sumsq = 1 / sqrt (sumsq);
    for (i = 0; i < v.length(); i++) // Apply scaling
        u(i) = v(i) * sumsq;
    return u;
}
// End of File
Previous Page | 1 | 2 | 3 | 4 | 5 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK