1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2011 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                 Eclipse Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#          http://www.eclipse.org/org/documents/epl-v10.html           #
11#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                    David Korn <dgkorn@gmail.com>                     #
18#                                                                      #
19########################################################################
20
21set -o nounset
22
23function test_arithmetric_expression_accesss_array_element_through_nameref
24{
25    compound out=( typeset stdout stderr ; integer res )
26    compound -r -a tests=(
27        (
28            cmd='@@TYPE@@ -a @@VAR@@ ;  @@VAR@@[1]=90 ;       function x { nameref nz=$1 ;              print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1]'        ; stdoutpattern=' 90==90'
29        )
30        (
31            cmd='@@TYPE@@ -a @@VAR@@=( [1]=90 ) ;             function x { nameref nz=$1 ;              print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1]'        ; stdoutpattern=' 90==90'
32        )
33        (
34            cmd='@@TYPE@@ -a @@VAR@@ ;  @@VAR@@[1][3]=90 ;    function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1][3]'    ; stdoutpattern=' 90==90'
35        )
36        (
37            cmd='@@TYPE@@ -a @@VAR@@=( [1][3]=90 ) ;          function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1][3]'    ; stdoutpattern=' 90==90'
38        )
39        (
40            cmd='@@TYPE@@ -a @@VAR@@ ;  @@VAR@@[1][3][5]=90 ; function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1][3][5]'    ; stdoutpattern=' 90==90'
41        )
42        (
43            cmd='@@TYPE@@ -a @@VAR@@=( [1][3][5]=90 ) ;       function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1][3][5]'    ; stdoutpattern=' 90==90'
44        )
45        (
46            cmd='@@TYPE@@ -a @@VAR@@ ;  @@VAR@@[1][3][5]=90 ; function x { nameref nz=${1}[$2][$3][$4] ; print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@ 1 3 5'    ; stdoutpattern=' 90==90'
47        )
48        (
49            cmd='@@TYPE@@ -A @@VAR@@ ;  @@VAR@@[1]=90 ;       function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1]'        ; stdoutpattern=' 90==90'
50        )
51        (
52            cmd='@@TYPE@@ -A @@VAR@@=( [1]=90 ) ;             function x { nameref nz=$1 ;               print " $(( round(nz) ))==$(( round($nz) ))" ; } ; x @@VAR@@[1]'        ; stdoutpattern=' 90==90'
53        )
54    )
55
56    typeset testname
57    integer i
58    typeset mode
59    typeset cmd
60
61    for (( i=0 ; i < ${#tests[@]} ; i++ )) ; do
62        # fixme: This list should include "typeset -lX" and "typeset -X" but ast-ksh.2010-03-09 fails like this:
63        # 'typeset -X -a z ;  z[1][3]=90 ; function x { nameref nz=$1 ; print " $(( nz ))==$(( $nz ))" ; } ; x z[1][3]'
64        # + typeset -X -a z
65        # + z[1][3]=90
66        # + x 'z[1][3]'
67        # /home/test001/bin/ksh[1]: x: line 1: x1.68000000000000000000000000000000p: no parent
68        for ty in \
69            'typeset' \
70            'integer' \
71            'float' \
72            'typeset -i' \
73            'typeset -si' \
74            'typeset -li' \
75            'typeset -E' \
76            'typeset -F' \
77            'typeset -X' \
78            'typeset -lE' \
79            'typeset -lX' \
80            'typeset -lF' ; do
81            for mode in \
82                'plain' \
83                'in_compound' \
84                'in_indexed_compound_array' \
85                'in_2d_indexed_compound_array' \
86                'in_4d_indexed_compound_array' \
87                'in_associative_compound_array' \
88                'in_compound_nameref' \
89                'in_indexed_compound_array_nameref' \
90                'in_2d_indexed_compound_array_nameref' \
91                'in_4d_indexed_compound_array_nameref' \
92                'in_associative_compound_array_nameref' \
93                 ; do
94                nameref tst=tests[i]
95                cmd="${tst.cmd//@@TYPE@@/${ty}}"
96                case "${mode}" in
97                    'plain')
98                        cmd="${cmd//@@VAR@@/z}"
99                        ;;
100
101                    'in_compound')
102                        cmd="compound c ; ${cmd//@@VAR@@/c.z}"
103                        ;;
104                    'in_indexed_compound_array')
105                        cmd="compound -a c ; ${cmd//@@VAR@@/c[11].z}"
106                        ;;
107                    'in_2d_indexed_compound_array')
108                        cmd="compound -a c ; ${cmd//@@VAR@@/c[17][19].z}"
109                        ;;
110                    'in_4d_indexed_compound_array')
111                        cmd="compound -a c ; ${cmd//@@VAR@@/c[17][19][23][27].z}"
112                        ;;
113                    'in_associative_compound_array')
114                        cmd="compound -A c ; ${cmd//@@VAR@@/c[info].z}"
115                        ;;
116
117                    'in_compound_nameref')
118                        cmd="compound c ; nameref ncr=c.z ; ${cmd//@@VAR@@/ncr}"
119                        ;;
120                    'in_indexed_compound_array_nameref')
121                        cmd="compound -a c ; nameref ncr=c[11].z ; ${cmd//@@VAR@@/ncr}"
122                        ;;
123                    'in_2d_indexed_compound_array_nameref')
124                        cmd="compound -a c ; nameref ncr=c[17][19].z ; ${cmd//@@VAR@@/ncr}"
125                        ;;
126                    'in_4d_indexed_compound_array_nameref')
127                        cmd="compound -a c ; nameref ncr=c[17][19][23][27].z ; ${cmd//@@VAR@@/ncr}"
128                        ;;
129                    'in_associative_compound_array_nameref')
130                        cmd="compound -A c ; nameref ncr=c[info].z ; ${cmd//@@VAR@@/ncr}"
131                        ;;
132                    *)
133                        log_error "Unexpected mode ${mode}"
134                        ;;
135                esac
136
137                testname="${0}/${cmd}"
138                out.stderr="${ { out.stdout="${ ${SHELL} -o nounset -o errexit -c "${cmd}" ; (( out.res=$? )) ; }" ; } 2>&1 ; }"
139#set +x
140
141                    [[ "${out.stdout}" == ${tst.stdoutpattern}      ]] || log_error "${testname}: Expected stdout to match $(printf '%q\n' "${tst.stdoutpattern}"), got $(printf '%q\n' "${out.stdout}")"
142                       [[ "${out.stderr}" == ''            ]] || log_error "${testname}: Expected empty stderr, got $(printf '%q\n' "${out.stderr}")"
143                (( out.res == 0 )) || log_error "${testname}: Unexpected exit code ${out.res}"
144            done
145        done
146    done
147
148    return 0
149}
150
151function test_has_iszero
152{
153    typeset str
154    integer i
155
156    typeset -r -a tests=(
157        '(( iszero(0)   )) && print "OK"'
158        '(( iszero(0.)  )) && print "OK"'
159        '(( iszero(-0)  )) && print "OK"'
160        '(( iszero(-0.) )) && print "OK"'
161        'float n=0.  ; (( iszero(n) )) && print "OK"'
162        'float n=+0. ; (( iszero(n) )) && print "OK"'
163        'float n=-0. ; (( iszero(n) )) && print "OK"'
164        'float n=1.  ; (( iszero(n) )) || print "OK"'
165        'float n=1.  ; (( iszero(n-1.) )) && print "OK"'
166        'float n=-1. ; (( iszero(n+1.) )) && print "OK"'
167    )
168
169    for (( i=0 ; i < ${#tests[@]} ; i++ )) ; do
170        str="$( ${SHELL} -o errexit -c "${tests[i]}" 2>&1 )" || log_error "test $i: returned non-zero exit code $?"
171        [[ "${str}" == 'OK' ]] || log_error "test $i: expected 'OK', got '${str}'"
172    done
173
174    return 0
175}
176
177# run tests
178test_arithmetric_expression_accesss_array_element_through_nameref
179test_has_iszero
180
181# ==========
182# Math functions
183
184# Rounds floating point numbers to 8 decimal places
185function roundto {
186    number=$1
187    printf '%.8f' $number
188}
189
190# acos
191expect=3.14159265
192actual=$(roundto $(( acos(-1) )) )
193[[ $actual -eq $expect ]] || log_error "acos failed" "$expect" "$actual"
194
195# ==========
196# acosh
197expect=5.19292599
198actual=$(roundto $(( acosh(90) )) )
199[[ $actual -eq $expect ]] || log_error "acosh failed" "$expect" "$actual"
200
201# ==========
202# asin
203expect=1.57079633
204actual=$(roundto $(( asin(1) )) )
205[[ $actual -eq $expect ]] || log_error "asin failed" "$expect" "$actual"
206
207# ==========
208# asinh
209expect=5.19298771
210actual=$(roundto $(( asinh(90) )) )
211[[ $actual -eq $expect ]] || log_error "asinh failed" "$expect" "$actual"
212
213# ==========
214# atan
215expect=1.55968567
216actual=$(roundto $(( atan(90) )) )
217[[ $actual -eq $expect ]] || log_error "atan failed" "$expect" "$actual"
218
219# ==========
220# atan2
221expect=0.78539816
222actual=$(roundto $(( atan2(90, 90) )) )
223[[ $actual -eq $expect ]] || log_error "atan2 failed" "$expect" "$actual"
224
225# ==========
226# atanh
227expect=0.54930614
228actual=$(roundto $(( atanh(0.5) )) )
229[[ $actual -eq $expect ]] || log_error "atanh failed" "$expect" "$actual"
230
231# ==========
232# cbrt
233expect=4.48140475
234actual=$(roundto $(( cbrt(90) )) )
235[[ $actual -eq $expect ]] || log_error "cbrt failed" "$expect" "$actual"
236
237# ==========
238# ceil
239expect=1.0
240actual=$(( ceil(0.1) ))
241[[ $actual -eq $expect ]] || log_error "ceil failed" "$expect" "$actual"
242
243# ==========
244# copysign
245if [[ $OS_NAME == cygwin* ]]
246then
247    log_warning 'copysignl() function is broken  on Cygwin'
248else
249    expect=-1.0
250    actual=$(roundto $(( copysign(1.0, -3) )) )
251    [[ $actual -eq $expect ]] || log_error "copysign failed" "$expect" "$actual"
252fi
253
254# ==========
255# cos
256expect=0.15425145
257actual=$(roundto $(( cos(30) )) )
258[[ $actual -eq $expect ]] || log_error "cos failed" "$expect" "$actual"
259
260# ==========
261# cosh
262expect=1.0
263actual=$(( cosh(0) ))
264[[ $actual -eq $expect ]] || log_error "cosh failed" "$expect" "$actual"
265
266# ==========
267# erf
268expect=0.84270079
269actual=$(roundto $(( erf(1) )) )
270[[ $actual -eq $expect ]] || log_error "erf failed" "$expect" "$actual"
271
272# ==========
273# erfc
274expect=0.15729921
275actual=$(roundto $(( erfc(1) )) )
276[[ $actual -eq $expect ]] || log_error "erfc failed" "$expect" "$actual"
277
278# ==========
279# exp
280expect=2.71828183
281actual=$(roundto $(( exp(1) )) )
282[[ $actual -eq $expect ]] || log_error "exp failed" "$expect" "$actual"
283
284# ==========
285# exp2
286expect=2
287actual=$(( exp2(1) ))
288[[ $actual -eq $expect ]] || log_error "exp2 failed" "$expect" "$actual"
289
290# ==========
291# expm1
292expect=1.71828183
293actual=$(roundto $(( expm1(1) )) )
294[[ $actual -eq $expect ]] || log_error "expm1 failed" "$expect" "$actual"
295
296# ==========
297# fabs
298expect=1.0
299actual=$(( fabs(-1) ))
300[[ $actual -eq $expect ]] || log_error "fabs failed" "$expect" "$actual"
301
302# ==========
303# abs
304expect=1
305actual=$(( abs(-1) ))
306[[ $actual -eq $expect ]] || log_error "abs failed" "$expect" "$actual"
307
308# ==========
309# fdim - Return positive difference between arguments
310expect=0
311actual=$(( fdim(1, 3) ))
312[[ $actual -eq $expect ]] || log_error "fdim failed" "$expect" "$actual"
313
314# ==========
315expect=2
316actual=$(( fdim(3, 1) ))
317[[ $actual -eq $expect ]] || log_error "fdim failed" "$expect" "$actual"
318
319# ==========
320# floor
321expect=-2
322actual=$(( floor(-1.5) ))
323[[ $actual -eq $expect ]] || log_error "floor failed" "$expect" "$actual"
324
325# ==========
326# fmax
327expect=1.1
328actual=$(( fmax(1.0, 1.1) ))
329[[ $actual -eq $expect ]] || log_error "fmax failed" "$expect" "$actual"
330
331# ==========
332# fmin
333expect=1.0
334actual=$(( fmin(1.0, 1.1) ))
335[[ $actual -eq $expect ]] || log_error "fmin failed" "$expect" "$actual"
336
337# ==========
338# finite
339expect=1
340actual=$(( finite(1.2) ))
341[[ $actual -eq $expect ]] || log_error "finite failed" "$expect" "$actual"
342
343expect=0
344actual=$(( finite(1.2 + inf) ))
345[[ $actual -eq $expect ]] || log_error "finite failed" "$expect" "$actual"
346
347expect=0
348actual=$(( finite(1.2 + nan) ))
349[[ $actual -eq $expect ]] || log_error "finite failed" "$expect" "$actual"
350
351# ==========
352# float
353expect=7.12345679
354actual=$(roundto $(( float(7.123456789) )) )
355[[ $actual -eq $expect ]] || log_error "float failed" "$expect" "$actual"
356
357# ==========
358# fmod
359expect=9.99
360actual=$(roundto $(( fmod(999.99, 10) )) )
361[[ $actual -eq $expect ]] || log_error "fmod failed" "$expect" "$actual"
362
363# ==========
364# int
365expect=2
366actual=$(( int(2.9) ))
367[[ $actual -eq $expect ]] || log_error "int failed" "$expect" "$actual"
368
369expect=-3
370actual=$(( int(-3.1) ))
371[[ $actual -eq $expect ]] || log_error "int failed" "$expect" "$actual"
372
373# ==========
374# isfinite
375expect=1
376actual=$(( isfinite(1) ))
377[[ $actual -eq $expect ]] || log_error "isfinite(1) failed" "$expect" "$actual"
378
379expect=0
380actual=$(( isfinite(1 * inf) ))
381[[ $actual -eq $expect ]] || log_error "isfinite(1) failed" "$expect" "$actual"
382
383# ==========
384# isunordered
385expect=0
386actual=$(( isunordered(1, 2) ))
387[[ $actual -eq $expect ]] || log_error "isless(1, 2) failed" "$expect" "$actual"
388
389expect=1
390actual=$(( isunordered(2, nan) ))
391[[ $actual -eq $expect ]] || log_error "isunordered(2, nan) failed" "$expect" "$actual"
392
393expect=1
394actual=$(( isunordered(nan, 2) ))
395[[ $actual -eq $expect ]] || log_error "isunordered(nan, 2) failed" "$expect" "$actual"
396
397# ==========
398# isless
399expect=1
400actual=$(( isless(1, 2) ))
401[[ $actual -eq $expect ]] || log_error "isless(1, 2) failed" "$expect" "$actual"
402
403expect=0
404actual=$(( isless(2, 1) ))
405[[ $actual -eq $expect ]] || log_error "isless(2, 1) failed" "$expect" "$actual"
406
407expect=0
408actual=$(( isless(nan, 2) ))
409[[ $actual -eq $expect ]] || log_error "isless(nan, 2) failed" "$expect" "$actual"
410
411# ==========
412# islessequal
413expect=1
414actual=$(( islessequal(1.1, 1.1) ))
415[[ $actual -eq $expect ]] || log_error "islessequal(1.1, 1.1) failed" "$expect" "$actual"
416
417expect=0
418actual=$(( islessequal(1.2, 1.1) ))
419[[ $actual -eq $expect ]] || log_error "islessequal(1.2, 1.1) failed" "$expect" "$actual"
420
421expect=1
422actual=$(( islessequal(1.1, 1.2) ))
423[[ $actual -eq $expect ]] || log_error "islessequal(1.1, 1.2) failed" "$expect" "$actual"
424
425# ==========
426# islessgreater
427expect=0
428actual=$(( islessgreater(1.1, 1.1) ))
429[[ $actual -eq $expect ]] || log_error "islessgreater(1.1, 1.1) failed" "$expect" "$actual"
430
431expect=1
432actual=$(( islessgreater(1.2, 1.1) ))
433[[ $actual -eq $expect ]] || log_error "islessgreater(1.2, 1.1) failed" "$expect" "$actual"
434
435expect=1
436actual=$(( islessgreater(1.1, 1.2) ))
437[[ $actual -eq $expect ]] || log_error "islessgreater(1.1, 1.2) failed" "$expect" "$actual"
438
439expect=0
440actual=$(( islessgreater(1.1, nan) ))
441[[ $actual -eq $expect ]] || log_error "islessgreater(1.1, nan) failed" "$expect" "$actual"
442
443# ==========
444# isgreater
445expect=0
446actual=$(( isgreater(1, 2) ))
447[[ $actual -eq $expect ]] || log_error "isgreater(1, 2) failed" "$expect" "$actual"
448
449expect=1
450actual=$(( isgreater(2, 1) ))
451[[ $actual -eq $expect ]] || log_error "isgreater(2, 1) failed" "$expect" "$actual"
452
453expect=0
454actual=$(( isgreater(2, nan) ))
455[[ $actual -eq $expect ]] || log_error "isgreater(2, nan) failed" "$expect" "$actual"
456
457# ==========
458# isgreaterequal
459expect=1
460actual=$(( isgreaterequal(1.1, 1.1) ))
461[[ $actual -eq $expect ]] || log_error "isgreaterequal(1.1, 1.1) failed" "$expect" "$actual"
462
463expect=1
464actual=$(( isgreaterequal(1.2, 1.1) ))
465[[ $actual -eq $expect ]] || log_error "isgreaterequal(1.2, 1.1) failed" "$expect" "$actual"
466
467expect=0
468actual=$(( isgreaterequal(1.1, 1.2) ))
469[[ $actual -eq $expect ]] || log_error "isgreaterequal(1.1, 1.2) failed" "$expect" "$actual"
470
471# ==========
472# isnan
473expect=0
474actual=$(( isnan(1.2) ))
475[[ $actual -eq $expect ]] || log_error "isnan(1.2) failed" "$expect" "$actual"
476
477expect=1
478actual=$(( isnan(sqrt(-1)) ))
479[[ $actual -eq $expect ]] || log_error "isnan(sqrt(-1)) failed" "$expect" "$actual"
480
481# ==========
482# isnormal
483expect=1
484actual=$(( isnormal(1.2) ))
485[[ $actual -eq $expect ]] || log_error "isnormal(1.2) failed" "$expect" "$actual"
486
487expect=0
488actual=$(( isnormal(-inf) ))
489[[ $actual -eq $expect ]] || log_error "isnormal(-inf) failed" "$expect" "$actual"
490
491# ==========
492# issubnormal
493expect=0
494actual=$(( issubnormal(1.2) ))
495[[ $actual -eq $expect ]] || log_error "issubnormal(1.2) failed" "$expect" "$actual"
496
497# ==========
498expect=0
499actual=$(( isgreater(2, 2) ))
500[[ $actual -eq $expect ]] || log_error "isgreater(2, 2) failed" "$expect" "$actual"
501
502# ==========
503expect=1
504actual=$(( isgreater(3, 2) ))
505[[ $actual -eq $expect ]] || log_error "isgreater(3, 2) failed" "$expect" "$actual"
506
507# ==========
508# isless
509expect=1
510actual=$(( isless(1, 2) ))
511[[ $actual -eq $expect ]] || log_error "isless(1, 2) failed" "$expect" "$actual"
512
513# ==========
514expect=0
515actual=$(( isless(2, 2) ))
516[[ $actual -eq $expect ]] || log_error "isless(2, 2) failed" "$expect" "$actual"
517
518# ==========
519expect=0
520actual=$(( isless(3, 2) ))
521[[ $actual -eq $expect ]] || log_error "isless(3, 2) failed" "$expect" "$actual"
522
523# ==========
524# iszero
525expect=1
526actual=$(( iszero(0) ))
527[[ $actual -eq $expect ]] || log_error "iszero(0) failed" "$expect" "$actual"
528
529expect=0
530actual=$(( iszero(1) ))
531[[ $actual -eq $expect ]] || log_error "iszero(1) failed" "$expect" "$actual"
532
533# ==========
534# isinf
535expect=0
536actual=$(( isinf(0) ))
537[[ $actual -eq $expect ]] || log_error "isinf(0) failed" "$expect" "$actual"
538
539expect=1
540actual=$(( isinf(-inf) ))
541[[ $actual -eq $expect ]] || log_error "isinf(-inf) failed" "$expect" "$actual"
542
543expect=1
544actual=$(( isinf(inf) ))
545[[ $actual -eq $expect ]] || log_error "isinf(inf) failed" "$expect" "$actual"
546
547# ==========
548# log
549expect=4.60517019
550actual=$(roundto $(( log(100) )) )
551[[ $actual -eq $expect ]] || log_error "log failed" "$expect" "$actual"
552
553# ==========
554# pow
555expect=65536
556actual=$(( pow(2, 16) ))
557[[ $actual -eq $expect ]] || log_error "pow failed" "$expect" "$actual"
558
559# ==========
560# remainder
561expect=4
562actual=$(( remainder(44, 10) ))
563[[ $actual -eq $expect ]] || log_error "remainder failed" "$expect" "$actual"
564
565# ==========
566# round
567expect=100
568actual=$(( round(99.9) ))
569[[ $actual -eq $expect ]] || log_error "round failed" "$expect" "$actual"
570
571# ==========
572# signbit
573expect=0
574actual=$(( signbit(1) ))
575[[ $actual -eq $expect ]] || log_error "signbit(1) failed" "$expect" "$actual"
576
577expect=1
578actual=$(( signbit(-1) ))
579[[ $actual -eq $expect ]] || log_error "signbit(-1) failed" "$expect" "$actual"
580
581# ==========
582# sin
583expect=0.89399666
584actual=$(roundto $(( sin(90) )) )
585[[ $actual -eq $expect ]] || log_error "sin failed" "$expect" "$actual"
586
587# ==========
588# sinh
589expect=1634508.68623590
590actual=$(roundto $(( sinh(15) )) )
591[[ $actual -eq $expect ]] || log_error "sinh failed" "$expect" "$actual"
592
593# ==========
594# sqrt
595expect=40
596actual=$(( sqrt(1600) ))
597[[ $actual -eq $expect ]] || log_error "sqrt failed" "$expect" "$actual"
598
599# ==========
600# tan
601expect=1.61977519
602actual=$(roundto $(( tan(45) )) )
603[[ $actual -eq $expect ]] || log_error "tan failed" "$expect" "$actual"
604
605# ==========
606# tanh
607expect=1
608actual=$(( tanh(45) ))
609[[ $actual -eq $expect ]] || log_error "tanh failed" "$expect" "$actual"
610
611# ==========
612# trunc
613expect=99
614actual=$(( trunc(99.9) ))
615[[ $actual -eq $expect ]] || log_error "trunc failed" "$expect" "$actual"
616
617# ==========
618# j0
619expect=0.76519769
620actual=$(roundto $(( j0(1) )) )
621[[ $actual -eq $expect ]] || log_error "j0 failed" "$expect" "$actual"
622
623# ==========
624# j1
625expect=0.44005059
626actual=$(roundto $(( j1(1) )) )
627[[ $actual -eq $expect ]] || log_error "j1 failed" "$expect" "$actual"
628
629# ==========
630# jn
631expect=0.57672481
632actual=$(roundto $(( jn(1, 2) )) )
633[[ $actual -eq $expect ]] || log_error "jn failed" "$expect" "$actual"
634
635# ==========
636# y0
637expect=0.08825696
638actual=$(roundto $(( y0(1) )) )
639[[ $actual -eq $expect ]] || log_error "y0 failed" "$expect" "$actual"
640
641# ==========
642# y1
643expect=-0.78121282
644actual=$(roundto $(( y1(1) )) )
645[[ $actual -eq $expect ]] || log_error "y1 failed" "$expect" "$actual"
646
647# ==========
648# yn
649expect=-0.10703243
650actual=$(roundto $(( yn(1, 2) )) )
651[[ $actual -eq $expect ]] || log_error "yn failed" "$expect" "$actual"
652