Hi, I encounter a bizzare behaviour for an inner constructor of a struct, and I am trying to understand what is happening. The first attempt was the following
struct Log_Float{T <: Integer, S <: Number}
sign::T ##sign of the number
val::S ##value of the log
##INNER CONSTRUCTOR
function Log_Float{T,S}(x::T, y::S) where T<:Integer where S<:Number
!(x in [-1, 1]) && throw(ArgumentError("Sign has to be ether plus or minus 1"))
return new(x, y)
end
end
But declaring in this form, and proceding by creating a Log_Float, I get the following error message:
ERROR: StackOverflowError:
Stacktrace:
[1] Main.Log_Floats.Log_Float(::Int64, ::Int64) at C:\Users\lucas\Desktop\Log_Floats.jl:17 (repeats 79984 times)
I tried different hands on way to solve this problem, as I created Structs with just one single parametric argument following the above structure many times, without having any problem (it’s the structure indicated on the Julia documentation). To solve the problem I had to write:
struct Log_Float{T <: Integer, S <: Number}
sign::T ##sign of the number
val::S ##value of the log
##INNER CONSTRUCTOR
function Log_Float(x::T, y::S) where T<:Integer where S<:Number
!(x in [-1, 1]) && throw(ArgumentError("Sign has to be ether plus or minus 1"))
return new{T,S}(x, y)
end
end
Any idea of what was the original problem, and why the second version solves the problem?