@@ -123,6 +123,20 @@ describe('INTERVAL JS COMPILATION - FUNCTIONS', () => {
123123 const fn = compile ( expr , { to : 'interval-js' } ) ;
124124 expect ( fn . code ) . toContain ( '_IA.piecewise' ) ;
125125 } ) ;
126+
127+ test ( 'compiles Gamma' , ( ) => {
128+ const expr = ce . parse ( '\\Gamma(x)' ) ;
129+ const fn = compile ( expr , { to : 'interval-js' } ) ;
130+ expect ( fn . success ) . toBe ( true ) ;
131+ expect ( fn . code ) . toContain ( '_IA.gamma' ) ;
132+ } ) ;
133+
134+ test ( 'compiles GammaLn' , ( ) => {
135+ const expr = ce . box ( [ 'GammaLn' , 'x' ] ) ;
136+ const fn = compile ( expr , { to : 'interval-js' } ) ;
137+ expect ( fn . success ) . toBe ( true ) ;
138+ expect ( fn . code ) . toContain ( '_IA.gammaln' ) ;
139+ } ) ;
126140} ) ;
127141
128142describe ( 'INTERVAL JS EXECUTION' , ( ) => {
@@ -421,4 +435,35 @@ describe('INTERVAL JS COMPLEX EXPRESSIONS', () => {
421435 expect ( result . value . lo ) . toBeCloseTo ( Math . exp ( - 1 ) , 5 ) ;
422436 expect ( result . value . hi ) . toBeCloseTo ( 1 , 5 ) ;
423437 } ) ;
438+
439+ test ( 'Gamma function positive values' , ( ) => {
440+ const expr = ce . parse ( '\\Gamma(x)' ) ;
441+ const fn = compile ( expr , { to : 'interval-js' } ) ;
442+
443+ // Gamma(2.5) ≈ 1.329
444+ const result = fn . run ! ( { x : { lo : 2.5 , hi : 2.5 } } ) ;
445+ expect ( result . kind ) . toBe ( 'interval' ) ;
446+ expect ( result . value . lo ) . toBeCloseTo ( 1.329 , 2 ) ;
447+ expect ( result . value . hi ) . toBeCloseTo ( 1.329 , 2 ) ;
448+ } ) ;
449+
450+ test ( 'Gamma function detects singularity at zero' , ( ) => {
451+ const expr = ce . parse ( '\\Gamma(x)' ) ;
452+ const fn = compile ( expr , { to : 'interval-js' } ) ;
453+
454+ // Interval crossing zero should detect the pole
455+ const result = fn . run ! ( { x : { lo : - 0.5 , hi : 0.5 } } ) ;
456+ expect ( result . kind ) . toBe ( 'singular' ) ;
457+ } ) ;
458+
459+ test ( 'GammaLn function' , ( ) => {
460+ const expr = ce . box ( [ 'GammaLn' , 'x' ] ) ;
461+ const fn = compile ( expr , { to : 'interval-js' } ) ;
462+
463+ // GammaLn(2.5) ≈ ln(1.329) ≈ 0.284
464+ const result = fn . run ! ( { x : { lo : 2.5 , hi : 2.5 } } ) ;
465+ expect ( result . kind ) . toBe ( 'interval' ) ;
466+ expect ( result . value . lo ) . toBeCloseTo ( 0.284 , 2 ) ;
467+ expect ( result . value . hi ) . toBeCloseTo ( 0.284 , 2 ) ;
468+ } ) ;
424469} ) ;
0 commit comments