Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Julian way of defining custom numeric types

$
0
0

Hello,

I am working with the DifferentialEquations package to play around some differential equations involving angles.

Instead of letting everything go on as a normal float and just afterwards reduce everything modulo 2pi for visualisation, i wanted to try to go the julian way and define a small wrapper for the Floag64 type

struct Angle <: Real
    x::Float64
end
Angle(x::Real) = Angle(x % 2pi)

Unfortunately this is not enough to make for a smooth addition to my program as julia struggles to convert and does not know what to do with this new type.

I know that i can extend all the base operations by hand, but i was left wondering if there is a smoother and easier way to let a simple primitive Number type wrapper just automatically fall in place the rest of the Julia implementation.

More in general i tried to look for some quick guidelines when creating a new custom type but i could not find one. Are there any Best Practices ™ when it comes to seamlessly embed a new custom type in the language?

Thanks!

7 posts - 5 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles