Air mass: Difference between revisions

12,531 bytes added ,  7 months ago
m
m (Python example)
m (→‎{{header|Wren}}: Minor tidy)
 
(14 intermediate revisions by 9 users not shown)
Line 16:
::     it flies in a specially retrofitted Boeing 747 about four flights a week.
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">V DEG = 0.017453292519943295769236907684886127134
V RE = 6371000
V dd = 0.001
V FIN = 10000000
 
F rho(a)
‘ the density of air as a function of height above sea level ’
R exp(-a / 8500.0)
 
F height(Float a; z, d)
a = altitude of observer
z = zenith angle (in degrees)
d = distance along line of sight
R sqrt((:RE + a) ^ 2 + d ^ 2 - 2 * d * (:RE + a) * cos((180 - z) * :DEG)) - :RE
 
F column_density(a, z)
‘ integrates density along the line of sight ’
V (dsum, d) = (0.0, 0.0)
L d < :FIN
V delta = max(:dd, (:dd) * d)
dsum += rho(height(a, z, d + 0.5 * delta)) * delta
d += delta
R dsum
 
F airmass(a, z)
R column_density(a, z) / column_density(a, 0)
 
print("Angle 0 m 13700 m\n "(‘-’ * 36))
L(z) (0.<91).step(5)
print(f:‘{z:3} {airmass(0, z):12.7} {airmass(13700, z):12.7}’)</syntaxhighlight>
 
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.0000000 1.0000000
5 1.0038096 1.0038096
10 1.0153847 1.0153848
15 1.0351774 1.0351776
20 1.0639905 1.0639909
25 1.1030594 1.1030601
30 1.1541897 1.1541908
35 1.2199808 1.2199825
40 1.3041893 1.3041919
45 1.4123417 1.4123457
50 1.5528040 1.5528102
55 1.7387592 1.7387692
60 1.9921200 1.9921366
65 2.3519974 2.3520272
70 2.8953137 2.8953729
75 3.7958235 3.7959615
80 5.5388581 5.5392811
85 10.0789622 10.0811598
90 34.3298114 34.3666656
</pre>
 
=={{header|Ada}}==
{{trans|C}}
{{works with|Ada 2012}}
<syntaxhighlight lang="ada">
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
 
procedure Main is
subtype double is Long_Float;
package double_io is new Ada.Text_IO.Float_IO (double);
use double_io;
package Elementary_Double is new Ada.Numerics.Generic_Elementary_Functions
(Float_Type => double);
use Elementary_Double;
 
-- degrees to radians
Deg : constant := 0.017_453_292_519_943_295_769_236_907_684_886_127_134;
 
-- Earth radius in meters
Re : constant := 6_371_000.0;
 
-- integrate in this fraction of the distance already covered
Dd : constant := 0.001;
 
-- integrate only to a height of 10000km. efectively infinity
Fin : constant := 10_000_000.0;
 
function rho (a : double) return double is (Exp (-a / 8_500.0));
 
function height (a : double; z : double; d : double) return double is
aa : double := Re + a;
hh : double :=
Sqrt (aa * aa + d * d - 2.0 * d * aa * Cos ((180.0 - z) * Deg));
begin
return hh - Re;
end height;
 
function column_density (a : double; z : double) return double is
sum : double := 0.0;
d : double := 0.0;
d_delta : double;
begin
while d < Fin loop
-- adaptive step size to avoid it taking forever
d_delta := Dd * d;
if d_delta < Dd then
d_delta := Dd;
end if;
sum := sum + rho (height (a, z, d + 0.5 * d_delta)) * d_delta;
d := d + d_delta;
end loop;
return sum;
end column_density;
 
function air_mass (a : double; z : double) return double is
(column_density (a, z) / column_density (a, 0.0));
 
z : double := 0.0;
begin
Put_Line ("Angle 0 m 13700 m");
Put_Line ("------------------------------------");
while z <= 90.0 loop
Put(Item => Integer(z), Width => 2);
Put (Item => air_mass (0.0, z), Fore => 8, Aft => 8, Exp => 0);
Put (Item => air_mass (13_700.0, z), Fore => 8, Aft => 8, Exp => 0);
New_Line;
z := z + 5.0;
end loop;
 
end Main;
</syntaxhighlight>
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.00000000 1.00000000
5 1.00380963 1.00380965
10 1.01538466 1.01538475
15 1.03517744 1.03517765
20 1.06399053 1.06399093
25 1.10305937 1.10306005
30 1.15418974 1.15419083
35 1.21998076 1.21998246
40 1.30418931 1.30419190
45 1.41234169 1.41234567
50 1.55280404 1.55281025
55 1.73875921 1.73876915
60 1.99212000 1.99213665
65 2.35199740 2.35202722
70 2.89531368 2.89537287
75 3.79582352 3.79596149
80 5.53885809 5.53928113
85 10.07896219 10.08115981
90 34.32981136 34.36666557
</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f AIR_MASS.AWK
# converted from FreeBASIC
Line 54 ⟶ 212:
}
function max(x,y) { return((x > y) ? x : y) }
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 78 ⟶ 236:
90 34.32981136 34.36666557
</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="freebasic">global RE, dd, LIM
RE = 6371000 #Earth radius in meters
dd = 0.001 #integrate in this fraction of the distance already covered
LIM = 10000000 #integrate only to a height of 10000km, effectively inLIMity
 
print "Angle 0 m 13700 m"
print "------------------------------------"
for z = 0 to 90 step 5
print rjust(z,2); " "; ljust(airmass(0, z),13,"0"); " "; ljust(airmass(13700, z),13,"0")
next z
end
 
function max(a, b)
if a > b then return a else return b
end function
 
function rho(a)
#the density of air as a function of height above sea level
return exp(-a/8500.0)
end function
 
function height(a, z, d)
#a = altitude of observer
#z = zenith angle (in degrees)
#d = distance along line of sight
AA = RE + a
HH = sqr(AA^2 + d^2 - 2*d*AA*cos(radians(180-z)))
return HH - RE
end function
 
function column_density(a, z)
#integrates density along the line of sight
sum = 0.0
d = 0.0
while d < LIM
delta = max(dd, (dd)*d) #adaptive step size to avoid it taking forever:
sum += rho(height(a, z, d+0.5*delta)) * delta
d += delta
end while
return sum
end function
 
function airmass(a, z)
return column_density(a, z) / column_density(a, 0)
end function</syntaxhighlight>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
#define DEG 0.017453292519943295769236907684886127134 'degrees to radians
#define RE 6371000 'Earth radius in meters
#define dd 0.001 'integrate in this fraction of the distance already covered
#define FIN 10000000 'integrate only to a height of 10000km, effectively infinity
#define max(a, b) iif(a>b,a,b)
 
function rho(a as double) as double
'the density of air as a function of height above sea level
return exp(-a/8500.0)
end function
 
function height( a as double, z as double, d as double ) as double
'a = altitude of observer
'z = zenith angle (in degrees)
'd = distance along line of sight
dim as double AA = RE + a, HH
HH = sqr( AA^2 + d^2 - 2*d*AA*cos((180-z)*DEG) )
return HH - RE
end function
 
function column_density( a as double, z as double ) as double
'integrates density along the line of sight
dim as double sum = 0.0, d = 0.0, delta
while d<FIN
delta = max(dd, (dd)*d) 'adaptive step size to avoid it taking forever:
sum += rho(height(a, z, d+0.5*delta))*delta
d += delta
wend
return sum
end function
 
function airmass( a as double, z as double ) as double
return column_density( a, z ) / column_density( a, 0 )
end function
 
print "Angle 0 m 13700 m"
print "------------------------------------"
for z as double = 0 to 90 step 5.0
print using "## ##.######## ##.########";z;airmass(0, z);airmass(13700, z)
next z
</syntaxhighlight>
 
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.00000000 1.00000000
5 1.00380963 1.00380965
10 1.01538466 1.01538475
15 1.03517744 1.03517765
20 1.06399053 1.06399093
25 1.10305937 1.10306005
30 1.15418974 1.15419083
35 1.21998076 1.21998246
40 1.30418931 1.30419190
45 1.41234169 1.41234567
50 1.55280404 1.55281025
55 1.73875921 1.73876915
60 1.99212000 1.99213665
65 2.35199740 2.35202722
70 2.89531368 2.89537287
75 3.79582352 3.79596149
80 5.53885809 5.53928113
85 10.07896219 10.08115981
90 34.32981136 34.36666557
</pre>
 
==={{header|True BASIC}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">FUNCTION max(a, b)
IF a > b then LET max = a else LET max = b
END FUNCTION
 
FUNCTION rho(a)
!the density of air as a function of height above sea level
LET rho = exp(-a/8500)
END FUNCTION
 
FUNCTION height(a, z, d)
!a = altitude of observer
!z = zenith angle (in degrees)
!d = distance along line of sight
LET aa = re+a
LET hh = sqr(aa^2+d^2-2*d*aa*cos((180-z)*deg))
LET height = hh-re
END FUNCTION
 
FUNCTION columndensity(a, z)
!integrates density along the line of sight
LET sum = 0
LET d = 0
DO while d < lim
LET delta = max(dd, (dd)*d) !adaptive step size to avoid it taking forever:
LET sum = sum+rho(height(a, z, d+.5*delta))*delta
LET d = d+delta
LOOP
LET columndensity = sum
END FUNCTION
 
FUNCTION airmass(a, z)
LET airmass = columndensity(a, z)/columndensity(a, 0)
END FUNCTION
 
LET deg = .0174532925199433 !degrees to radians
LET re = 6371000 !Earth radius in meters
LET dd = .001 !integrate in this fraction of the distance already covered
LET lim = 10000000 !integrate only to a height of 10000km, effectively infinity
PRINT "Angle 0 m 13700 m"
PRINT "------------------------------------"
FOR z = 0 to 90 step 5
PRINT using "## ##.######## ##.########": z, airmass(0, z), airmass(13700, z)
NEXT z
END</syntaxhighlight>
 
=={{header|C}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="c">#include <math.h>
#include <stdio.h>
 
Line 128 ⟶ 451:
z, airmass(0.0, z), airmass(13700.0, z));
}
}</langsyntaxhighlight>
 
{{out}}
Line 154 ⟶ 477:
90 34.32981136 34.36666557
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{trans|GO}}
{{libheader|SysUtils,StdCtrls}}
 
<syntaxhighlight lang="Delphi">
 
const RE = 6371000; { radius of earth in meters}
const DD = 0.001; { integrate in this fraction of the distance already covered}
const FIN = 1e7; { integrate only to a height of 10000km, effectively infinity}
 
function rho(a: double): double;
{ The density of air as a function of height above sea level.}
begin
Result:=Exp(-a / 8500);
end;
 
function Radians(degrees: double): double;
{ Converts degrees to radians}
begin
Result:= degrees * Pi / 180
end;
 
function Height(A, Z, D: double): double;
{ a = altitude of observer}
{ z = zenith angle (in degrees)}
{ d = distance along line of sight}
var AA,HH: double;
begin
AA := RE + A;
HH := Sqrt(AA*AA + D*D - 2*D*AA*Cos(Radians(180-z)));
Result:= HH - RE;
end;
 
function ColumnDensity(A, Z: double): double;
{ Integrates density along the line of sight.}
var Sum,D,Delta: double;
begin
Sum := 0.0;
D := 0.0;
while D < FIN do
begin
delta := Max(DD, DD*D); { adaptive step size to avoid it taking forever}
Sum:=Sum + Rho(Height(A, Z, D+0.5*Delta)) * Delta;
D:=D + delta;
end;
Result:= Sum;
end;
 
 
function AirMass(A, Z: double): double;
begin
Result:= ColumnDensity(A, Z) / ColumnDensity(a, 0);
end;
 
procedure ShowAirMass(Memo: TMemo);
var Z: integer;
begin
Memo.Lines.Add('Angle 0 m 13700 m');
Memo.Lines.Add('------------------------------------');
Z:=0;
while Z<=90 do
begin
Memo.Lines.Add(Format('%2d %11.8f %11.8f', [z, airmass(0, Z), airmass(13700, Z)]));
Z:=Z+5;
end;
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.00000000 1.00000000
5 1.00380963 1.00380965
10 1.01538466 1.01538475
15 1.03517744 1.03517765
20 1.06399053 1.06399093
25 1.10305937 1.10306005
30 1.15418974 1.15419083
35 1.21998076 1.21998246
40 1.30418931 1.30419190
45 1.41234169 1.41234567
50 1.55280404 1.55281025
55 1.73875921 1.73876915
60 1.99212000 1.99213665
65 2.35199740 2.35202722
70 2.89531368 2.89537287
75 3.79582352 3.79596149
80 5.53885809 5.53928113
85 10.07896219 10.08115981
90 34.32981136 34.36666557
 
Elapsed Time: 189.304 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
{{trans|FreeBASIC}}
 
<syntaxhighlight lang=easylang>
func rho a .
return pow 2.718281828459 (-a / 8500)
.
func height a z d .
AA = 6371000 + a
HH = sqrt (AA * AA + d * d - 2 * d * AA * cos (180 - z))
return HH - 6371000
.
func density a z .
while d < 10000000
delta = higher 0.001 (0.001 * d)
sum += rho height a z (d + 0.5 * delta) * delta
d += delta
.
return sum
.
func airmass a z .
return density a z / density a 0
.
numfmt 8 2
print "Angle 0 m 13700 m"
print "------------------------"
for z = 0 step 5 to 90
print z & " " & airmass 0 z & " " & airmass 13700 z
.
</syntaxhighlight>
 
=={{header|Factor}}==
{{trans|FreeBASIC}}
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: formatting io kernel math math.functions math.order
math.ranges math.trig sequences ;
 
Line 192 ⟶ 646:
dup [ 0 swap airmass ] [ 13700 swap airmass ] bi
"%2d %15.8f %17.8f\n" printf
] each</langsyntaxhighlight>
{{out}}
<pre>
Line 217 ⟶ 671:
90 34.32981136 34.36666557
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>
#define DEG 0.017453292519943295769236907684886127134 'degrees to radians
#define RE 6371000 'Earth radius in meters
#define dd 0.001 'integrate in this fraction of the distance already covered
#define FIN 10000000 'integrate only to a height of 10000km, effectively infinity
#define max(a, b) iif(a>b,a,b)
 
function rho(a as double) as double
'the density of air as a function of height above sea level
return exp(-a/8500.0)
end function
 
function height( a as double, z as double, d as double ) as double
'a = altitude of observer
'z = zenith angle (in degrees)
'd = distance along line of sight
dim as double AA = RE + a, HH
HH = sqr( AA^2 + d^2 - 2*d*AA*cos((180-z)*DEG) )
return HH - RE
end function
 
function column_density( a as double, z as double ) as double
'integrates density along the line of sight
dim as double sum = 0.0, d = 0.0, delta
while d<FIN
delta = max(dd, (dd)*d) 'adaptive step size to avoid it taking forever:
sum += rho(height(a, z, d+0.5*delta))*delta
d += delta
wend
return sum
end function
 
function airmass( a as double, z as double ) as double
return column_density( a, z ) / column_density( a, 0 )
end function
 
print "Angle 0 m 13700 m"
print "------------------------------------"
for z as double = 0 to 90 step 5.0
print using "## ##.######## ##.########";z;airmass(0, z);airmass(13700, z)
next z
</lang>
 
{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.00000000 1.00000000
5 1.00380963 1.00380965
10 1.01538466 1.01538475
15 1.03517744 1.03517765
20 1.06399053 1.06399093
25 1.10305937 1.10306005
30 1.15418974 1.15419083
35 1.21998076 1.21998246
40 1.30418931 1.30419190
45 1.41234169 1.41234567
50 1.55280404 1.55281025
55 1.73875921 1.73876915
60 1.99212000 1.99213665
65 2.35199740 2.35202722
70 2.89531368 2.89537287
75 3.79582352 3.79596149
80 5.53885809 5.53928113
85 10.07896219 10.08115981
90 34.32981136 34.36666557
</pre>
 
 
=={{header|Go}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 341 ⟶ 725:
fmt.Printf("%2d %11.8f %11.8f\n", z, airmass(0, fz), airmass(13700, fz))
}
}</langsyntaxhighlight>
 
{{out}}
Line 370 ⟶ 754:
=={{header|Java}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="java">public class AirMass {
public static void main(String[] args) {
System.out.println("Angle 0 m 13700 m");
Line 413 ⟶ 797:
private static final double DD = 0.001; // integrate in this fraction of the distance already covered
private static final double FIN = 10000000.0; // integrate only to a height of 10000km, effectively infinity
}</langsyntaxhighlight>
 
{{out}}
Line 446 ⟶ 830:
 
'''Preliminaries'''
<langsyntaxhighlight lang="jq">def pi: 4 * (1|atan);
 
def radians: . * pi / 180;
Line 470 ⟶ 854:
else . + "." + "0" * digits
end
| lpad($width);</langsyntaxhighlight>
'''Physics'''
<langsyntaxhighlight lang="jq"># constants
def RE: 6371000; # radius of earth in meters
def DD: 0.001; # integrate in this fraction of the distance already covered
Line 501 ⟶ 885:
"------------------------------------",
( range(0; 91; 5)
| "\(lpad(2)) \(airmass(0; .)|fmt(11;8)) \(airmass(13700; .)|fmt(11;8))" )</langsyntaxhighlight>
{{out}}
<pre>
Line 530 ⟶ 914:
=={{header|Julia}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="julia">using Printf
 
const DEG = 0.017453292519943295769236907684886127134 # degrees to radians
Line 562 ⟶ 946:
@printf("%2d %11.8f %11.8f\n", z, airmass(0, z), airmass(13700, z))
end
</langsyntaxhighlight>{{out}}
<pre>
Angle 0 m 13700 m
Line 589 ⟶ 973:
=={{header|Nim}}==
{{trans|Wren}}
<langsyntaxhighlight Nimlang="nim">import math, strformat
 
const
Line 628 ⟶ 1,012:
while z <= 90:
echo &"{z:2} {airmass(0, z):11.8f} {airmass(13700, z):11.8f}"
z += 5</langsyntaxhighlight>
 
{{out}}
Line 655 ⟶ 1,039:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature <say signatures>;
Line 701 ⟶ 1,085:
for my $z (map{ 5*$_ } 0..18) {
printf "%2d %11.8f %11.8f\n", $z, airmass(0, $z), airmass(13700, $z);
}</langsyntaxhighlight>
{{out}}
<pre>Angle 0 m 13700 m
Line 726 ⟶ 1,110:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">RE</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6371000</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">// radius of earth in meters</span>
<span style="color: #000000;">DD</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0.001</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">// integrate in this fraction of the distance already covered</span>
Line 762 ⟶ 1,146:
<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;">"%2d %11.8f %11.8f\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">z</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">airmass</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">z</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">airmass</span><span style="color: #0000FF;">(</span><span style="color: #000000;">13700</span><span style="color: #0000FF;">,</span><span style="color: #000000;">z</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 789 ⟶ 1,173:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">""" Rosetta Code task: Air_mass """
 
from math import sqrt, cos, exp
Line 818 ⟶ 1,202:
d += delta
return dsum
 
</lang>{{out}}
def airmass(a, z):
return column_density(a, z) / column_density(a, 0)
 
print('Angle 0 m 13700 m\n', '-' * 36)
for z in range(0, 91, 5):
print(f"{z: 3d} {airmass(0, z): 12.7f} {airmass(13700, z): 12.7f}")
</syntaxhighlight>{{out}}
<pre>
Angle 0 m 13700 m
------------------------------------
0 1.000 0000000 1.0000000000
5 1.004 0038096 1.0040038096
10 1.015 0153847 1.0150153848
15 1.035 0351774 1.0350351776
20 1.064 0639905 1.0640639909
25 1.103 1030594 1.1031030601
30 1.154 1541897 1.1541541908
35 1.220 2199808 1.2202199825
40 1.304 3041893 1.3043041919
45 1.412 4123417 1.4124123457
50 1.553 5528040 1.5535528102
55 1.739 7387592 1.7397387692
60 1.992 9921200 1.9929921366
65 2.352 3519974 2.3523520272
70 2.895 8953137 2.8958953729
75 3.796 7958235 3.7967959615
80 5.539 5388581 5.5395392811
85 10.079 0789622 10.0810811598
90 34.330 3298114 34.3673666656
</pre>
 
=={{header|Raku}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="raku" perl6line>constant DEG = pi/180; # degrees to radians
constant RE = 6371000; # Earth radius in meters
constant dd = 0.001; # integrate in this fraction of the distance already covered
Line 882 ⟶ 1,273:
say join "\n", (0, 5 ... 90).hyper(:3batch).map: -> \z {
sprintf "%2d %11.8f %11.8f", z, airmass( 0, z), airmass(13700, z);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 909 ⟶ 1,300:
=={{header|REXX}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="rexx">/*REXX pgm calculates the air mass above an observer and an object for various angles.*/
numeric digits (length(pi()) - length(.)) % 4 /*calculate the number of digits to use*/
parse arg aLO aHI aBY oHT . /*obtain optional arguments from the CL*/
Line 959 ⟶ 1,350:
sum= sum + rho( elev(a, z, d + 0.5*delta) ) * delta; d= d + delta
end /*while*/
return sum</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 984 ⟶ 1,375:
90 │ 34.32981136 34.36666557
─────┴─────────────────────────────────────────────────────────────
</pre>
 
=={{header|RPL}}==
{{trans|FreeBASIC}}
≪ → a ≪ a NEG 8500 / EXP ≫ ≫ ‘'''RHO'''’ STO
≪ ''''RHO'''(√(aa^2+D^2-2*aa*D*COS(180-Z))-re)' EVAL
≫ ‘'''COLD'''’ STO
6371000 3 PICK OVER + → a z re aa
≪ DEG
z 'Z' STO ''''COLD'''' { D 0 1E7 } 1E-7 ∫ DROP
0 'Z' STO ''''COLD'''' { D 0 1E7 } 1E-7 ∫ DROP /
≫ ≫ ‘'''AM'''’ STO
 
≪ { } 0 90 '''FOR''' z z + z '''AM''' + 5 '''STEP''' ≫
{{out}}
<pre>
1: { 0 1
5 1.00380686363
10 1.01537368745
15 1.03515302646
20 1.06394782383
25 1.10299392042
30 1.15409753978
35 1.21985818096
40 1.30403285254
45 1.41214767977
50 1.55256798138
55 1.73847475415
60 1.99177718552
65 2.35157928673
70 2.89478919419
75 3.79512945489
80 5.53784169364
85 10.0771111633
90 34.3235064081 }
</pre>
 
=={{header|Rust}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="rust">const RE: f64 = 6371000.0; // Earth radius in meters
const DD: f64 = 0.001; // integrate in this fraction of the distance already covered
const FIN: f64 = 10000000.0; // integrate only to a height of 10000km, effectively infinity
Line 1,038 ⟶ 1,467:
);
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,066 ⟶ 1,495:
=={{header|Seed7}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
Line 1,125 ⟶ 1,554:
writeln(airmass(13700.0, z) digits 8 lpad 17);
end for;
end func;</langsyntaxhighlight>
{{out}}
<pre>
Line 1,155 ⟶ 1,584:
{{trans|Go}}
 
<langsyntaxhighlight lang="swift">import Foundation
 
extension Double {
Line 1,202 ⟶ 1,631:
 
print(air)
}</langsyntaxhighlight>
 
{{out}}
Line 1,232 ⟶ 1,661:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Math
import "./fmt" for Fmt
 
// constants
Line 1,241 ⟶ 1,670:
 
// The density of air as a function of height above sea level.
var rho = Fn.new { |a| Math.exp(-a/8500).exp }
 
// a = altitude of observer
Line 1,257 ⟶ 1,686:
var d = 0
while (d < FIN) {
var delta = MathDD.max(DD, DD * d) // adaptive step size to avoid it taking forever
sum = sum + rho.call(height.call(a, z, d + 0.5 * delta)) * delta
d = d + delta
Line 1,272 ⟶ 1,701:
Fmt.print("$2d $11.8f $11.8f", z, airmass.call(0, z), airmass.call(13700, z))
z = z + 5
}</langsyntaxhighlight>
 
{{out}}
Line 1,301 ⟶ 1,730:
=={{header|XPL0}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight XPL0lang="xpl0">define DEG = 0.017453292519943295769236907684886127134; \degrees to radians
define RE = 6371000.; \Earth radius in meters
define DD = 0.001; \integrate in this fraction of the distance already covered
Line 1,353 ⟶ 1,782:
Z:= Z + 5.;
]
]</langsyntaxhighlight>
 
{{out}}
9,483

edits