@@ -21,7 +21,6 @@ use risingwave_common::types::{
2121} ;
2222use risingwave_expr:: { ExprError , Result , function} ;
2323use rust_decimal:: MathematicalOps ;
24- use special:: { Gamma , Primitive } ;
2524
2625#[ function( "add(*int, *int) -> auto" ) ]
2726#[ function( "add(decimal, decimal) -> auto" ) ]
@@ -448,13 +447,13 @@ pub fn decimal_trim_scale(d: Decimal) -> Decimal {
448447/// ----
449448/// NaN
450449///
451- /// statement error
450+ /// statement error overflow
452451/// SELECT gamma('-inf'::float8);
453452///
454453/// query R
455454/// SELECT gamma('0.5'::float8);
456455/// ----
457- /// 1.7724538509055159
456+ /// 1.772453850905516
458457///
459458/// query R
460459/// SELECT gamma('1'::float8);
@@ -481,16 +480,16 @@ pub fn decimal_trim_scale(d: Decimal) -> Decimal {
481480/// ----
482481/// 24
483482///
484- /// statement error
483+ /// statement error overflow
485484/// SELECT gamma('-1'::float8);
486485///
487- /// statement error
486+ /// statement error underflow
488487/// SELECT gamma('-1000.5'::float8);
489488///
490- /// statement error
489+ /// statement error overflow
491490/// SELECT gamma('0'::float8);
492491///
493- /// statement error
492+ /// statement error overflow
494493/// SELECT gamma('1000'::float8);
495494/// ```
496495#[ function( "gamma(float8) -> float8" ) ]
@@ -500,30 +499,18 @@ pub fn gamma_f64(input: F64) -> Result<F64> {
500499 return Ok ( result) ;
501500 } else if input. is_infinite ( ) {
502501 if input. is_negative ( ) {
503- return Err ( ExprError :: InvalidParam {
504- name : "gamma" ,
505- reason : "value out of range: overflow" . into ( ) ,
506- } ) ;
502+ return Err ( ExprError :: NumericOverflow ) ;
507503 }
508504 } else {
509- result = F64 :: from ( Gamma :: gamma ( input. 0 ) ) ;
505+ result = input. gamma ( ) ;
510506 if result. is_nan ( ) || result. is_infinite ( ) {
511507 if !result. is_zero ( ) {
512- return Err ( ExprError :: InvalidParam {
513- name : "gamma" ,
514- reason : "value out of range: overflow" . into ( ) ,
515- } ) ;
508+ return Err ( ExprError :: NumericOverflow ) ;
516509 } else {
517- return Err ( ExprError :: InvalidParam {
518- name : "gamma" ,
519- reason : "value out of range: underflow" . into ( ) ,
520- } ) ;
510+ return Err ( ExprError :: NumericUnderflow ) ;
521511 }
522512 } else if result. is_zero ( ) {
523- return Err ( ExprError :: InvalidParam {
524- name : "gamma" ,
525- reason : "value out of range: underflow" . into ( ) ,
526- } ) ;
513+ return Err ( ExprError :: NumericUnderflow ) ;
527514 }
528515 }
529516 Ok ( result)
@@ -575,33 +562,30 @@ pub fn gamma_f64(input: F64) -> Result<F64> {
575562/// ----
576563/// 3.1780538303479458
577564///
578- /// statement error
565+ /// statement error overflow
579566/// SELECT lgamma('-1'::float8);
580567///
581568/// query R
582569/// SELECT lgamma('-1000.5'::float8);
583570/// ----
584571/// -5914.437701116853
585572///
586- /// statement error
573+ /// statement error overflow
587574/// SELECT gamma('0'::float8);
588575///
589576/// query R
590577/// SELECT lgamma('1000'::float8);
591578/// ----
592579/// 5905.220423209181
593580///
594- /// statement error
581+ /// statement error overflow
595582/// SELECT gamma('1e308'::float8);
596583/// ```
597584#[ function( "lgamma(float8) -> float8" ) ]
598585pub fn lgamma_f64 ( input : F64 ) -> Result < F64 > {
599- let ( result, _sign) = input. 0 . lgamma ( ) ;
586+ let ( result, _sign) = input. ln_gamma ( ) ;
600587 if result. is_infinite ( ) && input. is_finite ( ) {
601- return Err ( ExprError :: InvalidParam {
602- name : "lgamma" ,
603- reason : "value out of range: overflow" . into ( ) ,
604- } ) ;
588+ return Err ( ExprError :: NumericOverflow ) ;
605589 }
606590 Ok ( F64 :: from ( result) )
607591}
0 commit comments