Horizontal sundial calculations: Difference between revisions

m
→‎{{header|Haskell}}: (minor tidying)
(Added Perl example)
m (→‎{{header|Haskell}}: (minor tidying))
Line 1,018:
 
=={{header|Haskell}}==
<lang haskell>moduleroundDec Rosetta.HorSunDial:: whereInt -> Double -> Double
roundDec d = (/ 10.0 ^ d) . fromIntegral . round . (* 10.0 ^ d)
 
radToDegr = ((180 / pi) *)
roundDec :: Int -> Double -> Double
roundDec d = (/10.0^d). fromIntegral. round. (*10.0^d)
 
radToDegrdegrToRad = ((180/pi / 180) *)
degrToRad = ((pi/180)*)
 
main = do
let lat = -4.95
long = -150.5
legalMerid = -150
sinOfLat = sin $ degrToRad lat
diff = legalMerid - long
(putStrLn . unlines)
putStrLn $ [ "Latitude " ++ show lat
putStrLn $ , "Longitude " ++ show long
putStrLn $ , "Legal meridian " ++ show legalMerid
putStrLn $ , "Sine of latitude " ++ show (roundDec 6 sinOfLat)
putStrLn $ , "Diff longitude " ++ show (-diff)
putStrLn , "hour sun hour angle dial hour line angle"
mapM_ (\h -> ]
mapM_
let sha = diff + 15*h
(\h ->
dhla = radToDegr . atan. (sinOfLat *). tan $ degrToRad sha
in putStrLn $ take 7 (showlet hsha ++= repeatdiff '+ ')15 * h
dhla = radToDegr . atan . (sinOfLat *) . tan $ degrToRad sha
++ take 16 (show (roundDec 3 sha) ++ repeat ' ' )
++ " " ++ showin (roundDecputStrLn 3 dhla)$
take 7 (show h ++ repeat ' ') ++
) [-6,-5..6]</lang>
++ take 16 (show (roundDec 3 sha) ++ repeat ' ' ) ++
" " ++ show (roundDec 3 dhla))
) [-6,-5 .. 6]</lang>
{{out}}
<pre>*Rosetta.HorSunDial> main
9,659

edits