in

.NET Opensource

Community for opensource projects by Christoph Rüegg

Scalar operations for vector

Last post 05-22-2008 16:20 by Christoph Rüegg. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-21-2008 18:35

    Scalar operations for vector

    Is there any objections against adding operators for addition of scalars to vectors?

    #region Arithmetic Operator Overloading 

            /// <summary>
            /// Addition of scalar to a vector
            /// </summary>
            public static
            Vector
            operator +(
                Vector v,
                double s
                )
            {
                for (int i = 0; i < v.Length; i++)
                {
                    v._data[i] += s;
                }
                return v;
            }

            /// <summary>
            /// Addition of scalar to a vector
            /// </summary>
            public static
            Vector
            operator +(
                double s,
                Vector v
                )
            {
                for (int i = 0; i < v.Length; i++)
                {
                    v._data[i] += s;
                }
                return v;
            }

            /// <summary>
            /// Subtraction of scalar from a vector
            /// </summary>
            public static
            Vector
            operator -(
                double s,
                Vector v
                )
            {
                for (int i = 0; i < v.Length; i++)
                {
                    v._data[i] -= s;
                }
                return v;
            }

            /// <summary>
            /// Subtraction of scalar from a vector
            /// </summary>
            public static
            Vector
            operator -(
                Vector v,
                double s
                )
            {
                for (int i = 0; i < v.Length; i++)
                {
                    v._data[i] -= s;
                }
                return v;
            }

    Filed under: ,
  • 05-21-2008 18:59 In reply to

    Re: Scalar operations for vector

    Answer

    No, not from my side. Matlab supports it too, seems to be standard.

    But the implementation should not be in-place, i.e. a static operator + or - should never change the parameter vector v.

  • 05-22-2008 16:20 In reply to

    Re: Scalar operations for vector

    This feature is now tracked as IRID-148

Page 1 of 1 (3 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems