@@ -3,6 +3,7 @@ package numberfunc
33import (
44 "context"
55 "math"
6+ "math/big"
67
78 "github.com/hashicorp/terraform-plugin-framework/function"
89 "github.com/hashicorp/terraform-plugin-log/tflog"
@@ -30,11 +31,11 @@ func (*modFunction) Definition(_ context.Context, _ function.DefinitionRequest,
3031 Summary : "Determine modulus of a number" ,
3132 MarkdownDescription : "Return the remainder of the dividend number divided by the divisor number." ,
3233 Parameters : []function.Parameter {
33- function.Float64Parameter {
34+ function.NumberParameter {
3435 Name : "dividend" ,
3536 Description : "The dividend number from which to divide." ,
3637 },
37- function.Float64Parameter {
38+ function.NumberParameter {
3839 Name : "divisor" ,
3940 Description : "The divisor number by which to divide." ,
4041 },
@@ -45,7 +46,7 @@ func (*modFunction) Definition(_ context.Context, _ function.DefinitionRequest,
4546
4647func (* modFunction ) Run (ctx context.Context , req function.RunRequest , resp * function.RunResponse ) {
4748 // initialize input parameters
48- var dividend , divisor float64
49+ var dividend , divisor * big. Float
4950
5051 resp .Error = req .Arguments .Get (ctx , & dividend , & divisor )
5152 if resp .Error != nil {
@@ -55,14 +56,27 @@ func (*modFunction) Run(ctx context.Context, req function.RunRequest, resp *func
5556 ctx = tflog .SetField (ctx , "mod: dividend" , dividend )
5657 ctx = tflog .SetField (ctx , "mod: divisor" , divisor )
5758
59+ // convert to float64
60+ floatDividend , _ := dividend .Float64 ()
61+ if math .IsNaN (floatDividend ) || math .IsInf (floatDividend , 0 ) {
62+ resp .Error = function .ConcatFuncErrors (resp .Error , function .NewArgumentFuncError (0 , "mod: dividend is beyond the limits of float64" ))
63+ }
64+ floatDivisor , _ := divisor .Float64 ()
65+ if math .IsNaN (floatDivisor ) || math .IsInf (floatDivisor , 0 ) {
66+ resp .Error = function .ConcatFuncErrors (resp .Error , function .NewArgumentFuncError (1 , "mod: divisor is beyond the limits of float64" ))
67+ }
68+ if resp .Error != nil {
69+ return
70+ }
71+
5872 // validate input parameters
59- if divisor == 0 {
73+ if floatDivisor == 0 {
6074 resp .Error = function .NewArgumentFuncError (1 , "mod: divisor cannot be zero" )
6175 return
6276 }
6377
6478 // determine the modulus
65- modulus := math .Mod (dividend , divisor )
79+ modulus := math .Mod (floatDividend , floatDivisor )
6680 ctx = tflog .SetField (ctx , "mod: modulus" , modulus )
6781
6882 // store the result as a float64
0 commit comments