Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/tests/nofib/spectral/fish/Vector.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module Vector
where


-- A vector is a pair of floats

type Nr = Int
type Vec = (Nr, Nr)

(x1, y1) `vec_add` (x2, y2) = (x1+x2, y1+y2)

vec_add :: Vec -> Vec -> Vec
--  This adds two vectors.

(x1, y1) `vec_sub` (x2, y2) = (x1-x2, y1-y2)

vec_sub :: Vec -> Vec -> Vec
 -- This substracts the second vector from the first.

scale_vec (x, y) factor = (factor*x, factor*y)

scale_vec :: Vec -> Nr -> Vec
-- This performs scalar multiplication of the vector by a (Nr) factor.

scale_vec2 (x, y) a b = ((x*a) `div` b, (y*a) `div` b)

-- This function is provided for efficiency.
-- The first argument is vector.
-- The second argument and third arguments are integers.
-- These integers represent the nummerator and denominator of a rational
-- number which is used to scale the given vector.
-- If a' and b' are the Nr versions of a and b, then this function
-- computes:
--    (x*a/b, y*a/b).


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].