Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,19 @@
def pi: 4 * (1|atan);
def deg2rad: . * pi / 180;
def rad2deg: if . == null then null else . * 180 / pi end;
# Input: [x,y] (special handling of x==0)
# Output: [r, theta] where theta may be null
def to_polar:
if .[0] == 0
then [1, if .[1] > 5e-14 then pi/2 elif .[1] < -5e-14 then -pi/2 else null end]
else [1, ((.[1]/.[0]) | atan)]
end;
def from_polar: .[1] | [ cos, sin];
def abs: if . < 0 then - . else . end;
def summation(f): map(f) | add;

View file

@ -0,0 +1,15 @@
# input: degrees
def mean_angle:
def round:
if . == null then null
elif . < 0 then -1 * ((- .) | round) | if . == -0 then 0 else . end
else ((. + 3e-14) | floor) as $x
| if ($x - .) | abs < 3e-14 then $x else . end
end;
map( [1, deg2rad] | from_polar)
| [ summation(.[0]), summation(.[1]) ]
| to_polar
| .[1]
| rad2deg
| round;

View file

@ -0,0 +1,2 @@
([350, 10], [90, 180, 270, 360], [10, 20, 30])
| "The mean angle of \(.) is: \(mean_angle)"

View file

@ -0,0 +1,4 @@
jq -r -n -f Mean_angle.jq
The mean angle of [350,10] is: 0
The mean angle of [90,180,270,360] is: null
The mean angle of [10,20,30] is: 20