Anonymous user
Angles (geometric), normalization and conversion: Difference between revisions
Angles (geometric), normalization and conversion (view source)
Revision as of 02:04, 1 November 2021
, 2 years ago→{{header|Haskell}}: fixed the zero representation
m (→{{header|Haskell}}: minor details) |
m (→{{header|Haskell}}: fixed the zero representation) |
||
Line 1,485:
instance Show Rad where
show (Rad 0) = printf "∠0"
show (Rad r) = printf "∠%.3f" r
Line 1,497 ⟶ 1,498:
instance Show Deg where
show (Deg
show (Deg d) = printf "%.3g°" d
instance Angle Deg where
Line 1,509 ⟶ 1,511:
instance Show Grad where
show (Grad 0) = printf "0g"
show (Grad g) = printf "%.3gg" g
Line 1,521 ⟶ 1,524:
instance Show Mil where
show (Mil 0) = printf "0m"
show (Mil m) = printf "%.3gm" m
Line 1,527 ⟶ 1,531:
mkAngle = Mil
value (Mil m) = m
-- example of non-linear angular unit
Line 1,533 ⟶ 1,538:
instance Show Slope where
show (Slope
show (Slope m) = printf "%.g" (m * 100) ++ "%"
instance Angle Slope where
Line 1,546 ⟶ 1,552:
<pre>λ> angle 45 :: Deg
45.000
λ> angle pi :: Rad
Line 1,555 ⟶ 1,561:
λ> normalize 450 :: Deg
90.000
λ> normalize 450 :: Gon
Line 1,575 ⟶ 1,581:
λ> from @Gon @Deg (angle 100)
90.000
λ> to @Gon (angle @Deg 45)
Line 1,620 ⟶ 1,626:
<pre>λ> main
converting to radians
[∠-2.000,∠-1.000,∠0
[∠-0.035,∠-0.017,∠0
[∠-0.031,∠-0.016,∠0
[∠-0.002,∠-0.001,∠0
[∠-1.107,∠-0.785,∠0
converting to degrees
[-114.592
[-2.000
[-1.800
[-0.112
[-63.435
converting to grads
[-127.324g,-63.662g,
[-2.222g,-1.111g,
[-2.000g,-1.000g,
[-0.125g,-6.250e-2g,
[-70.483g,-50.000g,
converting to mils
[-2037.183m,-1018.592m,
[-35.556m,-17.778m,
[-32.000m,-16.000m,
[-2.000m,-1.000m,
[-1127.732m,-800.000m,
=={{header|J}}==
|