@@ -907,21 +907,16 @@ unit_pow(PG_FUNCTION_ARGS)
907
907
PG_RETURN_POINTER (result );
908
908
}
909
909
910
- PG_FUNCTION_INFO_V1 (unit_sqrt );
911
-
912
- Datum
913
- unit_sqrt (PG_FUNCTION_ARGS )
910
+ void
911
+ unit_sqrt_internal (Unit * a , Unit * result )
914
912
{
915
- Unit * a = (Unit * ) PG_GETARG_POINTER (0 );
916
- Unit * result ;
917
913
int i ;
918
914
919
915
/* compute root of value */
920
916
if (a -> value < 0 )
921
917
ereport (ERROR ,
922
918
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
923
919
errmsg ("cannot take square root of a negative-valued unit" )));
924
- result = (Unit * ) palloc (sizeof (Unit ));
925
920
result -> value = sqrt (a -> value );
926
921
927
922
/* compute root of base units */
@@ -934,7 +929,17 @@ unit_sqrt(PG_FUNCTION_ARGS)
934
929
base_units [i ])));
935
930
result -> units [i ] = a -> units [i ] >> 1 ;
936
931
}
932
+ }
933
+
934
+ PG_FUNCTION_INFO_V1 (unit_sqrt );
935
+
936
+ Datum
937
+ unit_sqrt (PG_FUNCTION_ARGS )
938
+ {
939
+ Unit * a = (Unit * ) PG_GETARG_POINTER (0 );
940
+ Unit * result = (Unit * ) palloc (sizeof (Unit ));
937
941
942
+ unit_sqrt_internal (a , result );
938
943
PG_RETURN_POINTER (result );
939
944
}
940
945
@@ -965,6 +970,105 @@ unit_cbrt(PG_FUNCTION_ARGS)
965
970
PG_RETURN_POINTER (result );
966
971
}
967
972
973
+ void
974
+ unit_exp_internal (Unit * a , Unit * result )
975
+ {
976
+ int i ;
977
+
978
+ /* compute exp of value */
979
+ result -> value = exp (a -> value );
980
+
981
+ /* check dimension */
982
+ for (i = 0 ; i < N_UNITS ; i ++ )
983
+ {
984
+ if (a -> units [i ] != 0 )
985
+ ereport (ERROR ,
986
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
987
+ errmsg ("cannot take base-e exponent of value that is not dimension-less" )));
988
+ result -> units [i ] = 0 ;
989
+ }
990
+ }
991
+
992
+ void
993
+ unit_ln_internal (Unit * a , Unit * result )
994
+ {
995
+ int i ;
996
+
997
+ /* compute ln of value */
998
+ result -> value = log (a -> value );
999
+
1000
+ /* check dimension */
1001
+ for (i = 0 ; i < N_UNITS ; i ++ )
1002
+ {
1003
+ if (a -> units [i ] != 0 )
1004
+ ereport (ERROR ,
1005
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
1006
+ errmsg ("cannot take ln of value that is not dimension-less" )));
1007
+ result -> units [i ] = 0 ;
1008
+ }
1009
+ }
1010
+
1011
+ void
1012
+ unit_log2_internal (Unit * a , Unit * result )
1013
+ {
1014
+ int i ;
1015
+
1016
+ /* compute log2 of value */
1017
+ result -> value = log2 (a -> value );
1018
+
1019
+ /* check dimension */
1020
+ for (i = 0 ; i < N_UNITS ; i ++ )
1021
+ {
1022
+ if (a -> units [i ] != 0 )
1023
+ ereport (ERROR ,
1024
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
1025
+ errmsg ("cannot take log2 of value that is not dimension-less" )));
1026
+ result -> units [i ] = 0 ;
1027
+ }
1028
+ }
1029
+
1030
+ void
1031
+ unit_asin_internal (Unit * a , Unit * result )
1032
+ {
1033
+ int i ;
1034
+
1035
+ /* compute asin of value */
1036
+ if (a -> value < -1 || a -> value > 1 )
1037
+ ereport (ERROR ,
1038
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
1039
+ errmsg ("cannot asin of values outside the range -1 to 1" )));
1040
+ result -> value = asin (a -> value );
1041
+
1042
+ /* check dimension */
1043
+ for (i = 0 ; i < N_UNITS ; i ++ )
1044
+ {
1045
+ if (a -> units [i ] != 0 )
1046
+ ereport (ERROR ,
1047
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
1048
+ errmsg ("cannot take asin of value that is not dimension-less" )));
1049
+ result -> units [i ] = 0 ;
1050
+ }
1051
+ }
1052
+
1053
+ void
1054
+ unit_tan_internal (Unit * a , Unit * result )
1055
+ {
1056
+ int i ;
1057
+
1058
+ /* compute tan of value */
1059
+ result -> value = tan (a -> value );
1060
+
1061
+ /* check dimension */
1062
+ for (i = 0 ; i < N_UNITS ; i ++ )
1063
+ {
1064
+ if (a -> units [i ] != 0 )
1065
+ ereport (ERROR ,
1066
+ (errcode (ERRCODE_INVALID_ARGUMENT_FOR_POWER_FUNCTION ),
1067
+ errmsg ("cannot take tan of value that is not dimension-less" )));
1068
+ result -> units [i ] = 0 ;
1069
+ }
1070
+ }
1071
+
968
1072
/* obsolete version of unit_at_text used in v1..3 */
969
1073
/* needs search_path = @extschema@ due to use of unit_parse() */
970
1074
PG_FUNCTION_INFO_V1 (unit_at );
0 commit comments