Horizontal sundial calculations: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 16:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V lat = Float(input(‘Enter latitude => ’))
V lng = Float(input(‘Enter longitude => ’))
V ref = Float(input(‘Enter legal meridian => ’))
Line 31:
hra -= lng - ref
V hla = degrees(atan(slat * tan(radians(hra))))
print(‘HR=#3; HRA=#3.3; HLA=#3.3’.format(h, hra, hla))</langsyntaxhighlight>
 
{{out}}
Line 61:
{{trans|ALGOL 68}}
sundial.adb:
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
Line 105:
end;
end loop;
end Sundial;</langsyntaxhighlight>
{{out}}
<pre>Enter latitude: -4.95
Line 142:
> Simon
-->
<langsyntaxhighlight lang="algol68">BEGIN
REAL lat, slat, lng, ref;
print ( "Enter latitude => " ); read (lat);
Line 165:
new line(stand out)
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 195:
{{trans|F#}}
AutoHotkey is not a command-line programming language, let me make that clear. However, in translating the F# I found that the command line really is best for this type of app. The first 3 comments in the script describe the workarounds used to interface with the commandline.
<langsyntaxhighlight AutoHotkeylang="autohotkey">DllCall("AllocConsole") ; Open a console window for this application
Pi := 4*ATan(1)
,Degrees := Pi/180
Line 226:
FileAppend, %clockhour%`t`t%shr%`t`t%dhla%`n, CONOUT$
}
MsgBox close me when done.</langsyntaxhighlight>
{{out}}
<pre>Enter Latitude:-4.95
Line 252:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f HORIZONTAL_SUNDIAL_CALCULATIONS.AWK
BEGIN {
Line 270:
function dr(x) { return x * 3.14159265 / 180 } # degrees to radians
function rd(x) { return x * 180 / 3.14159265 } # radians to degrees
</syntaxhighlight>
</lang>
<p>output:</p>
<pre>
Line 297:
{{works with|QBasic}}
{{trans|ALGOL-68}}
<langsyntaxhighlight lang="gwbasic">
10 REM Horizontal sundial calculations
20 DEF FNM(X) = INT(X*1000+0.5)/1000
Line 323:
240 NEXT H
250 END
</syntaxhighlight>
</lang>
 
==={{header|BASIC256}}===
<langsyntaxhighlight BASIC256lang="basic256">call SolarhoraAngle(-4.95, -150.5, -150.0)
end
 
Line 359:
print time; ap$; chr(9); hra; chr(9); chr(9); hla
next hora
end subroutine</langsyntaxhighlight>
 
==={{header|True BASIC}}===
<langsyntaxhighlight lang="qbasic">FUNCTION rad2deg(theta)
LET rad2deg = theta*180/PI
END FUNCTION
Line 382:
PRINT USING "## ####.## ####.###": hora, hra, hla
NEXT hora
END</langsyntaxhighlight>
 
==={{header|Yabasic}}===
<langsyntaxhighlight lang="yabasic">SolarHourAngle(-4.95, -150.5, -150.0)
end
 
Line 412:
print time using "##", ap$, chr$(9), hra using "####.##", chr$(9), chr$(9), hla using "####.###"
next hour
end sub</langsyntaxhighlight>
 
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"FNUSING"
INPUT "Enter latitude (degrees) : " latitude
Line 430:
IF ABS(hra) > 90 hla += 180 * SGN(hra * latitude)
PRINT FNusing("##.##", hour), FNusing(" ####.### ", hra), FNusing(" ####.###", hla)
NEXT hour</langsyntaxhighlight>
{{out}}
(note the correct '''negative''' value for time 18:00)
Line 454:
=={{header|C}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <math.h>
 
Line 496:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
namespace RosettaCode
Line 530:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <cmath>
#include <iostream>
#include <numbers>
Line 595:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 618:
=={{header|COBOL}}==
{{works with|OpenCOBOL}}
<langsyntaxhighlight lang="cobol">PROGRAM-ID. horizontal-sundial-calc.
 
DATA DIVISION.
Line 671:
dial-hour-line-angle-disp
END-PERFORM
.</langsyntaxhighlight>
 
{{out}}
Line 700:
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang="d">import std.stdio, std.math, std.conv, std.string;
 
double radians(in double x) pure nothrow { return x * (PI / 180); }
Line 727:
writefln("HR=%3d; HRA=%7.3f; HLA=%7.3f", h, hra, hla);
}
}</langsyntaxhighlight>
{{out|Example run}}
<pre>Enter latitude => -4.95
Line 756:
=={{header|DWScript}}==
{{trans|Java}}
<langsyntaxhighlight lang="delphi">procedure PrintSundial(lat, lng, lme : Float);
begin
PrintLn(Format('latitude: %7.2f', [lat]));
Line 778:
end;
 
PrintSundial(-4.95, -150.5, -150);</langsyntaxhighlight>
{{out}}
<pre>latitude: -4.95
Line 802:
 
=={{header|EasyLang}}==
<syntaxhighlight lang="text">func getn s$ . v .
write s$
v = number input
Line 821:
hla = atan2 (slat * sin hra) cos hra
print h + 12 & "\t" & hra & "\t\t" & hla
.</langsyntaxhighlight>
 
=={{header|ERRE}}==
<langsyntaxhighlight ERRElang="erre">PROGRAM SUN_DIAL
 
FUNCTION RAD(X)
Line 852:
 
END PROGRAM
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 878:
=={{header|Euphoria}}==
{{works with|OpenEuphoria}}
<syntaxhighlight lang="euphoria">
<lang Euphoria>
include std/console.e
include std/mathcons.e
Line 914:
 
if getc(0) then end if
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 939:
=={{header|F_Sharp|F#}}==
{{trans|C#}}
<langsyntaxhighlight lang="fsharp">// Learn more about F# at http://fsharp.net
 
open System
Line 974:
//To keep the console window open, can be omitted with block comment (" (* comment *) ")
Console.WriteLine("Press any key to continue...")
Console.ReadKey() |> ignore</langsyntaxhighlight>
{{out|Example output}}
<pre>
Line 1,004:
=={{header|Factor}}==
{{trans|Java}}
<langsyntaxhighlight lang="factor">USING: formatting io kernel locals math math.functions math.libm
math.parser math.ranges math.trig sequences ;
IN: rosetta-code.sundial
Line 1,035:
: sundial-demo ( -- ) get-input nl 3dup .diff nl .angles ;
 
MAIN: sundial-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 1,062:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: faccept ( -- f )
pad 32 accept pad swap >float 0= throw ;
: >radians ( deg -- rad ) 180e f/ pi f* ;
Line 1,080:
fdup f. ." , "
>radians fsincos fswap frot f* fswap fatan2 >degrees f.
loop fdrop fdrop ;</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{works with|gfortran}} with <tt>-fbackslash</tt> option
<langsyntaxhighlight lang="fortran">program SunDial
 
real :: lat, slat, lng, ref
Line 1,128:
end function rd
 
end program SunDial</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
{{trans|BBC BASIC}}
<langsyntaxhighlight lang="freebasic">' version 04-11-2016
' compile with: fbc -s console
 
Line 1,166:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre> Enter latitude (degrees): -4.95
Line 1,188:
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">window 1
 
def fn rad2deg( theta as double ) as double = theta * 180 / pi
Line 1,212:
fn SolarHourAngle( -4.95, -150.5, -150.0 )
 
HandleEvents</langsyntaxhighlight>
 
Output:
Line 1,240:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,272:
fmt.Printf("%2.0f %8.3f %8.3f\n", h, hra, hla)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,301:
{{trans|ALGOL 68}}
{{works with|PC-BASIC|any}}
<langsyntaxhighlight lang="qbasic">
10 ' Horizontal sundial calculations
20 PRINT "Enter latitude => ";
Line 1,325:
220 NEXT H%
230 END
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,352:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">roundDec :: Int -> Double -> Double
roundDec d = (/ 10.0 ^ d) . fromIntegral . round . (* 10.0 ^ d)
 
Line 1,381:
take 16 (show (roundDec 3 sha) ++ repeat ' ') ++
" " ++ show (roundDec 3 dhla))
[-6,-5 .. 6]</langsyntaxhighlight>
{{out}}
<pre>*Rosetta.HorSunDial> main
Line 1,405:
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
PrintSundial(-4.95, -150.5, -150);
end
Line 1,428:
" HRA=",hra,", HLA=",hla)
}
end</langsyntaxhighlight>
{{out}}
<pre>latitude: -4.95
Line 1,452:
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "SunDial.bas"
110 OPTION ANGLE RADIANS
120 TEXT 80
Line 1,467:
230 LET HLA=ATN(S*TAN(HRA*DR))*RD
240 PRINT "HR = ";H,"HRA =";HRA,"HLA =";HLA
250 NEXT</langsyntaxhighlight>
 
=={{header|J}}==
<langsyntaxhighlight lang="j">require 'trig'
atan2=: {:@*.@j. NB. arc tangent of y divided by x
Line 1,484:
r=.((,. (,. (atan2 *&slat)/@+.@r.&.rfd)) diff + 15&*) i:6
smoutput lbl ,: ('3.0';'7.3';'7.3') 8!:1 r
)</langsyntaxhighlight>
{{out|Example}}
<langsyntaxhighlight lang="j"> horiz _4.95 _150.5 _150
Latitude _4.95
Longitude _150.5
Line 1,508:
│ 5 │ 75.500 │-18.451 │
│ 6 │ 90.500 │-95.775 │
└──────┴────────────────┴────────────────────┘</langsyntaxhighlight>
 
=={{header|Java}}==
{{trans|C}} (Substitutes in atan2 for the hour line angle calculation)
<langsyntaxhighlight lang="java">import java.util.Scanner;
 
public class Sundial {
Line 1,543:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Enter latitude: -4.95
Line 1,569:
=={{header|Julia}}==
{{trans|Python}}
<langsyntaxhighlight lang="julia">
print("Enter latitude => ")
lat = parse(Float64, readline(STDIN))
Line 1,590:
@printf "HR = %3d; HRA = %7.3f; HLA = %7.3f\n" h hra hla
end
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,619:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">import java.lang.Math.atan2
import java.lang.Math.cos
import java.lang.Math.sin
Line 1,651:
println("%2d %s %+7.3f %+7.3f".format(hr, am, sha, dhla))
}
}</langsyntaxhighlight>
Sample input/output:
{{out}}
Line 1,683:
=={{header|Liberty BASIC}}==
Based on Algol & BBC BASIC versions. Note Liberty BASIC works in radians.
<langsyntaxhighlight lang="lb">global pi
pi = 3.14159265
input "Enter latitude (degrees) : "; latitude ' -4.95
Line 1,708:
function sgn(x)
if x > 0 then sgn = 1 else sgn = -1
end function</langsyntaxhighlight>
{{out}}
<pre>
Line 1,733:
=={{header|LiveCode}}==
Translation of BASIC versions.
<langsyntaxhighlight LiveCodelang="livecode">on mouseUp
ask "Enter lng,lat,meridian"
if it is empty then exit mouseup
Line 1,760:
function sgn x
if x >0 then return 1 else return -1
end sgn</langsyntaxhighlight>
 
=={{header|Logo}}==
<langsyntaxhighlight lang="logo">type "|Enter latitude: |
make "lat readword
type "|Enter longitude: |
Line 1,775:
make "hla arctan product sin :lat quotient sin :hra cos :hra
print (sentence "hour :hour ": :hra ", :hla)
]</langsyntaxhighlight>
 
=={{header|Lua}}==
{{trans|Python}}
<langsyntaxhighlight lang="lua">io.write("Enter latitude => ")
lat = tonumber(io.read())
 
Line 1,802:
hla = math.deg(math.atan(slat * math.tan(math.rad(hra))))
print(string.format("HR=%3d; HRA=%7.3f; HLA=%7.3f", h, hra, hla))
end</langsyntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">lat = Input["latitude", -4.95];
lng = Input["longitude", -150.5];
ref = Input["legal meridian", -150];
Line 1,818:
{h, -6, 6}
] // Prepend[{"Hour", "Sun hour angle",
"Dial hour line angle"}] // Grid</langsyntaxhighlight>
{{out}}
<pre>Hour Sun hour angle Dial hour line angle
Line 1,837:
=={{header|Microsoft Small Basic}}==
{{trans|ALGOL-68}}
<langsyntaxhighlight lang="microsoftsmallbasic">
TextWindow.Write("Enter latitude => ")
lat = TextWindow.ReadNumber()
Line 1,867:
TextWindow.WriteLine("")
EndFor
</syntaxhighlight>
</lang>
{{out}}
 
Line 1,893:
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">МГ П2 -> МГ П1 -> МГ sin П0
6 /-/ П3
ИП3 1 5 * ИП1 ИП2 - - П4
tg ИП0 * arctg ИП4 ИП3 С/П
ИП3 1 + П3 7 - x=0 12
Сx С/П</langsyntaxhighlight>
 
''Input'': ''latitude'' ^ ''longitude'' ^ ''legal meridian'' С/П ... С/П ...; switch of the angle measure set to ''Г''.
Line 1,909:
{{trans|ALGOL-68}}
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<langsyntaxhighlight lang="modula2">
MODULE SunDial;
 
Line 1,959:
END;
END SunDial.
</syntaxhighlight>
</lang>
{{out}}
Enter latitude => -4.95
Line 1,985:
=={{header|newLISP}}==
{{trans|Lua}}
<langsyntaxhighlight newLISPlang="newlisp">(define pi 3.141592654)
(define (radians degrees) (mul degrees (div pi 180)))
(define (degrees radians) (mul radians (div 180 pi)))
Line 2,013:
)
 
(exit)</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">import rdstdin, strutils, math, strformat
let lat = parseFloat readLineFromStdin "Enter latitude => "
Line 2,033:
let hra = float(15 * h) - lng + med
let hla = arctan(slat * tan(hra.degToRad)).radToDeg
echo &"HR={h:3d}; HRA={hra:7.3f}; HLA={hla:7.3f}"</langsyntaxhighlight>
 
{{out}}
Line 2,060:
=={{header|Objeck}}==
{{trans|C#}}
<langsyntaxhighlight lang="objeck">
class Sundial {
function : Main(args : String[]) ~ Nil {
Line 2,086:
}
}
</syntaxhighlight>
</lang>
 
=={{header|OCaml}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight lang="ocaml">let () =
let pi = 4. *. atan 1. in
print_endline "Enter latitude => ";
Line 2,113:
Printf.printf "HR= %3d; \t HRA=%7.3f; \t HLA= %7.3f\n" h hra hla;
done
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,143:
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">lat = input("Enter latitude: ");
lng = input("Enter longitude: ");
ref = input("Enter legal meridian: ");
Line 2,154:
hlas = atand( tand(hras) .* slat );
printf("HR= %3d; \t HRA=%7.3f; \t HLA= %7.3f\n",
[ [-6:6]; hras; hlas] );</langsyntaxhighlight>
 
=={{header|OoRexx}}==
{{trans|REXX}}
<langsyntaxhighlight lang="oorexx">/*REXX pgm shows: hour, sun hour angle, dial hour line angle, 6am ---> 6pm*/
/* Use trigonometric functions provided by rxCalc */
parse arg lat lng mer . /*get the optional arguments from the CL*/
Line 2,195:
sep: say indent copies('-',w1) copies('-',w2) copies('-',w3)
Return
::Requires rxMath Library</langsyntaxhighlight>
{{out}}
Not the same as for REXX anymore as the REXX computer programming example has been updated.
 
=={{header|Pascal}}==
<langsyntaxhighlight lang="pascal">Program SunDial;
 
Const
Line 2,235:
tab, ' HLA= ', hla:7:3)
end
end.</langsyntaxhighlight>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use utf8;
binmode STDOUT, ":utf8";
 
Line 2,263:
printf "%2d %s %8.3f %8.3f\n",
($hour + 12) % 12 || 12, ($hour < 0 ? 'AM' : 'PM'), $sun_deg, $line_deg;
}</langsyntaxhighlight>
{{out}}
<pre>Enter latitude => -4.95
Line 2,289:
=={{header|Phix}}==
For better behaviour/proper input on pwa/p2js I suppose this should really be a pGUI app.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">prompt</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">text</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">atom</span> <span style="color: #000000;">v</span><span style="color: #0000FF;">)</span>
Line 2,331:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3d:00%s %12.3f %17.3f\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">hour12</span><span style="color: #0000FF;">,</span><span style="color: #000000;">am</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ha</span><span style="color: #0000FF;">,</span><span style="color: #000000;">hla</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,360:
=={{header|PicoLisp}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/math.l")
 
(de prompt (Str . Arg)
Line 2,385:
(align 8 (round Hra))
"; HLA="
(align 8 (round Hla)) ) ) ) ) ) )</langsyntaxhighlight>
{{out}}
<pre>Enter latitude => -4.95
Line 2,410:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Get-Sundial
{
Line 2,461:
$sundial | Select-Object -Property "Sine of Latitude", "Longitude Difference" | Format-List
$sundial.Hours | Format-Table -AutoSize
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,491:
=={{header|PureBasic}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight PureBasiclang="purebasic">If OpenConsole()
Define.f lat, slat, lng, ref
Define.i h
Line 2,512:
Next
EndIf</langsyntaxhighlight>
{{out}}
<pre>Enter latitude => -4.95
Line 2,539:
=={{header|Python}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight lang="python">from __future__ import print_function
import math
try: raw_input
Line 2,559:
hra -= lng - ref
hla = math.degrees(math.atan(slat * math.tan(math.radians(hra))))
print("HR=%3d; HRA=%7.3f; HLA=%7.3f" % (h, hra, hla))</langsyntaxhighlight>
{{out}}
<pre>
Line 2,592:
Also, I apologize for the length; I added quite a bit of commenting, and I peeled things out into functions so I could test them. Hopefully, the result--though longer--is also more readable.
 
<langsyntaxhighlight Racketlang="racket">#lang racket
 
;; print the table for a given latitude and longitude-offset,
Line 2,669:
(check-= (to-hla -30 90) -90 1e-5)
(check < (to-hla -30 91) -90)
</syntaxhighlight>
</lang>
{{Out}}
<pre>Welcome to DrRacket, version 5.3.3.5--2013-02-20(5eddac74/d) [3m].
Line 2,698:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>sub postfix:<°> ($a) { $a * pi / 180 } # degrees to radians
sub postfix:<®> ($a) { $a * 180 / pi } # radians to degrees
 
Line 2,716:
printf "%2d %s %7.3f %7.3f\n",
($hour + 12) % 12 || 12, ($hour < 0 ?? 'AM' !! 'PM'), $sun_deg, $line_deg;
}</langsyntaxhighlight>
{{out|Example output}}
<pre>
Line 2,751:
 
No attempt was made to explain the inner workings of the trigonometric functions.
<langsyntaxhighlight lang="rexx">/*REXX program displays: hour, sun hour angle, dial hour line angle, 6am ───► 6pm. */
numeric digits length( pi() ) - length(.) /*in case sundial is in polar regions. */
parse arg lat lng . /*obtain optional arguments from the CL*/
Line 2,825:
m.=9; numeric form; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_ % 2
do j=0 while h>9; m.j= h; h= h % 2 + 1; end /*j*/
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g) *.5; end /*k*/; return g</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 2,895:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Horizontal sundial calculations
 
Line 2,920:
see "" + hour + " " + hra + " " + hla + nl
next
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,945:
{{trans|ALGOL 68}}
{{trans|Python}}
<langsyntaxhighlight lang="ruby">include Math
DtoR = PI/180
 
Line 2,967:
hla = atan( slat * tan( hra * DtoR ))/ DtoR
puts "HR =%3d; HRA =%7.3f; HLA =%7.3f" % [h, hra, hla]
end</langsyntaxhighlight>
{{out}}
<pre>
Line 2,994:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">global pi
pi = 22 / 7
Line 3,022:
if x >0 then sgn =1 else sgn =-1
end function
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,045:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::io;
struct SundialCalculation {
Line 3,096:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,124:
 
=={{header|Sather}}==
<langsyntaxhighlight lang="sather">class MAIN is
 
getvalue(s:STR):FLT is
Line 3,155:
end;
end;
end;</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">import java.util.Scanner
 
import scala.math.{atan2, cos, sin, toDegrees, toRadians}
Line 3,184:
}
 
}</langsyntaxhighlight>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 3,223:
"; HLA= " <& hla digits 3 lpad 7);
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>Enter latitude: -4.95
Line 3,249:
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var latitude = read('Enter latitude => ', Number)
var longitude = read('Enter longitude => ', Number)
var meridian = read('Enter legal meridian => ', Number)
Line 3,271:
printf("%2d %s  %7.3f  %7.3f\n",
(hour + 12) % 12 || 12, (hour < 0 ? 'AM' : 'PM'), sun_deg, line_deg)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,298:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<langsyntaxhighlight lang="smalltalk">|lat slat lng ref hra hla pi|
pi := 1 arcTan * 4.
'Enter latitude: ' display. lat := stdin nextLine asNumber.
Line 3,314:
hla := (hra degreesToRadians tan * slat) arcTan radiansToDegrees.
('HR= %1; %4 HRA=%2; %4 HLA= %3' % { h. hra. hla. $<9> }) displayNl.
]</langsyntaxhighlight>
 
=={{header|Tcl}}==
{{trans|ALGOL 68}}
<langsyntaxhighlight lang="tcl">set PI 3.1415927
fconfigure stdout -buffering none
puts -nonewline "Enter latitude => "; gets stdin lat
Line 3,336:
set hla [expr {atan($slat * tan($hra*$PI/180)) * 180/$PI}]
puts [format "HR=%+3d; HRA=%+8.3f; HLA=%+8.3f" $h $hra $hla]
}</langsyntaxhighlight>
{{out|Sample output}}
<pre>
Line 3,365:
{{trans|Go}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "io" for Stdin, Stdout
import "/fmt" for Fmt
 
Line 3,393:
var hla = (slat*s).atan(c) * 180 / Num.pi
Fmt.print("$2.0f $8.3f $8.3f", h, hra, hla)
}</langsyntaxhighlight>
 
{{out}}
Line 3,424:
{{libheader|libc}}
It must be linked with the C standard library and startup code.
<langsyntaxhighlight lang="asm"> global main
extern printf, scanf
 
Line 3,560:
 
o_ft:
db "HR= %3d; ",9," HRA=%7.3f; ",9," HLA= %7.3f", 10, 0</langsyntaxhighlight>
 
=={{header|XBasic}}==
{{trans|ALGOL-68}}
{{works with|Windows XBasic}}
<langsyntaxhighlight lang="xbasic">
PROGRAM "sundial"
VERSION "0.0001"
Line 3,593:
END FUNCTION
END PROGRAM
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,620:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">inc c:\cxpl\codes;
def Pi = 3.14159265358979323846,
Deg2Rad = Pi/180.0,
Line 3,645:
RlOut(0, HA); ChOut(0, Tab); RlOut(0, HLA); CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 3,671:
=={{header|zkl}}==
{{trans|F#}}
<langsyntaxhighlight lang="zkl">//(degree measure)*Degrees => Radian measure
//(radian measure)/Degrees => Degree measure
const pi=(0.0).pi, toDeg=(0.0).pi/180;
Line 3,693:
dhla :=(sineLatitude*(shr*toDeg).tan()).atan()/toDeg;
Console.writeln("%s\t\t%5.1f\t\t%+7.3f".fmt(clockHour,shr,dhla));
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,726:
=={{header|ZX Spectrum Basic}}==
{{trans|ERRE}}
<langsyntaxhighlight lang="zxbasic">10 DEF FN r(x)=x*PI/180
20 DEF FN d(x)=x*180/PI
30 INPUT "Enter latitude (degrees): ";latitude
Line 3,742:
150 IF ABS (hra)>90 THEN LET hla=hla+180*SGN (hra*latitude)
160 PRINT h;" ";hra;" ";hla
170 NEXT h</langsyntaxhighlight>
10,333

edits