From a3a0b1256b73c6a83254f877e2921d43574f4319 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sat, 12 Jul 2025 21:23:39 +0200 Subject: [PATCH] Add doc with ai --- .gitignore | 1 + README.md | 9 +++++++++ upnp/utils_bool.go | 8 +++++--- upnp/utils_float.go | 7 +++++++ upnp/utils_int.go | 5 +++++ upnp/utils_numeric_operandes.go | 2 ++ upnp/utils_time.go | 4 ++++ 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index faf81a59..12a8668f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ **/*.log **/*.old xxx +/dcai/ \ No newline at end of file diff --git a/README.md b/README.md index e69de29b..bd5a3eb5 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,9 @@ + +## Installing documentation system Doc-Gen + +https://github.com/fynnfluegge/doc-comments-ai + + +for f in upnp/*.go ; do + dcai/bin/aicomment --ollama-model deepseek-coder:33b-instruct $f +done \ No newline at end of file diff --git a/upnp/utils_bool.go b/upnp/utils_bool.go index 130fe566..13fbfed5 100644 --- a/upnp/utils_bool.go +++ b/upnp/utils_bool.go @@ -48,12 +48,14 @@ func toBool(val interface{}) (bool, error) { } } +// cmpBool compares two boolean values 'a' and 'b'. If they are equal it returns 0, if 'a' is false and 'b' is true it returns -1 else it returns 1. func cmpBool(a, b bool) int { - if a == b { + if a == b { // if both booleans are the same, return 0 return 0 } - if !a && b { + if !a && b { // if 'a' is false and 'b' is true, return -1 return -1 } - return 1 + // otherwise, return 1 + return 1 // if 'a' is true or 'a' and 'b' are not the same } diff --git a/upnp/utils_float.go b/upnp/utils_float.go index a749ec60..4bac44eb 100644 --- a/upnp/utils_float.go +++ b/upnp/utils_float.go @@ -6,6 +6,8 @@ import ( "strconv" ) +// maxFloat returns the maximum value for floating point numbers given number of bits. +// If bits is neither 32 nor 64, it defaults to returning the maximum float64 value. func maxFloat(bits int) float64 { switch bits { case 32: @@ -17,6 +19,9 @@ func maxFloat(bits int) float64 { } } +// minFloat returns the minimum float value for the given number of bits. +// If bits are not recognized as either 32 or 64, it will default to the maximum +// possible float64 value. func minFloat(bits int) float64 { switch bits { case 32: @@ -76,6 +81,8 @@ func toFloat(v interface{}, bits int) (float64, error) { return f, nil } +// cmpFloat64 compares two float64 values and returns an integer indicating their relation. +// If a is less than b, it returns -1; if a is greater than b, it returns 1; otherwise, it returns 0. func cmpFloat64(a, b float64) int { switch { case a < b: diff --git a/upnp/utils_int.go b/upnp/utils_int.go index 846d06d3..324ad669 100644 --- a/upnp/utils_int.go +++ b/upnp/utils_int.go @@ -115,6 +115,7 @@ func checkIntBounds(v int64, bits int) (int64, error) { return v, nil } +// cmpInt compares two integers 'a' and 'b'. If 'a' is less than 'b', it returns -1, if 'a' is greater than 'b' it returns 1, else it returns 0. func cmpInt(a, b int64) int { switch { case a < b: @@ -126,6 +127,10 @@ func cmpInt(a, b int64) int { } } +// cmpUint compares two unsigned integers, a and b. +// It returns -1 if a < b. +// It returns 1 if a > b. +// It returns 0 if a == b. func cmpUint(a, b uint64) int { switch { case a < b: diff --git a/upnp/utils_numeric_operandes.go b/upnp/utils_numeric_operandes.go index 52b749be..933f503e 100644 --- a/upnp/utils_numeric_operandes.go +++ b/upnp/utils_numeric_operandes.go @@ -2,6 +2,8 @@ package upnp import "fmt" +// valuesToNumericOperands takes two interface{} values, casts them to a numeric type based on a given StateVarType, and returns their float64 equivalents. +// If any error occurs during casting or conversion to float64, it is returned along with zero values for the operands. func valuesToNumericOperands(t StateVarType, a interface{}, b interface{}) (float64, float64, error) { var err error if !t.IsNumeric() { diff --git a/upnp/utils_time.go b/upnp/utils_time.go index 0b206af0..fee0daf2 100644 --- a/upnp/utils_time.go +++ b/upnp/utils_time.go @@ -5,6 +5,8 @@ import ( "time" ) +// toTime converts the given value to a time.Time type if possible, otherwise it returns an error. +// The supported types for conversion are: time.Time, string, int64 and float64. func toTime(v interface{}) (time.Time, error) { switch val := v.(type) { case time.Time: @@ -43,6 +45,8 @@ func toTime(v interface{}) (time.Time, error) { } } +// cmpTime compares two time.Times, returning -1 if the first is before the second, +// 1 if the first is after the second, and 0 if they're equal. func cmpTime(a, b time.Time) int { switch { case a.Before(b):