-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FAQ: document why system-specific Float alias doesn't make sense #12188
Comments
There isn't really a "system floating point". Making |
This has been discussed multiple times on various mailing lists and probably in GitHub issues. Should probably have an FAQ entry. Changing this to a documentation issues. |
Yes, that seems fine. The real reason I thought it might be useful since it is not entirely clear on the best way (i.e. most performant) to write code that is independent of system architecture. |
When I was a Julia newbie I interpreted For that reason I've always wanted an analogous So long as the addition of one would not confuse other segments of Julia's userbase such as those coming from C or C++, I would be strongly in favor of @yuyichao's proposal. |
I'm concerned that it will. There is already similar confusion between |
The idea that your system's word size determines a preferred floating-point size is a misconception that should be corrected, not something that should be catered to and reinforced. Hence, the doc tag. |
What was the rationale for allowing |
Because your system's word size does determine a preferred integer size. |
Wouldn't the preferred integer size imply the preferred floating point size since floating points can be represented as the division of two integers and are rational. |
The representability of floats as rationals has nothing to do with how they are represented in hardware. And if you mean by this statement that 64-bit floats can be represented as the ratio of 64-bit integers, then it is not even a true statement. |
I was more referring that significand, base, and exponent of a floating point number are integers although they are not 64 bit integers Which I guess answers my question. If 64 bit integers implies preferred floating point it would be |
You are assuming that modern hardware shares logic between floating point and integer operations, which is mostly not true. |
Ok, I am no expert on floating point implementation. Im just pulling things from wikipedia. Anyway I found a link to a previous discussion that explains it well enough for me. |
It was mentioned that it is bad form to have abstract types in record fields. I am assuming that the best way to handle both type foo{T<:FloatingPoint}
x::T
end for type definitions and function foo{T<:FloatingPoint}(x::T)
println(typeof(x))
end for functions. |
FWIW, at least making |
That should be the way to do it for type parameters.
This is not necessary since the compiler will specialize on the type of
The parameter here is usually necessary (unless you only want to accept |
Will the compiler specialize on the type . That is to say is it equivalent to writing function foo(x::Array{Float32})
println(typeof(x))
end
function foo(x::Array{Float64})
println(typeof(x))
end |
Yes. For most of the cases, specifying type parameter on a _function_ won't cause the compiler to specialize the code more. It's only important for distinguishing different types. In another word, the function will be as effecient even if you just write |
@lstagner in 32 bit architectures Did I understand correctly? Please correct me if I'm mistaken so I can update the FAQ, thanks! |
Sounds about right. 32 vs. 64 bit floats is less about system architecture and more about numerical precision. I believe the conflation of the two concepts is the primary source of the confusion. |
An argument in favor of having a type alias of |
that python link is unrelated to this discussion. The sensible default size for floating point number is always Float64, unless your algorithm demands something else. Unlike Int, it has nothing to do with the host processor. |
@vtjnash - Right, but having a |
This would be actively confusing since in C |
I see. In that case |
How so? See |
Given recurrent questions/suggestions on this subject, I wonder if the absence of a |
I'd rather actually consider removing the system-dependent |
@tkelman - What I meant by "no other type requires such a size specifier" is that I can just use e.g. the default |
Even though I don't personally care about the 32 bit stone age, I expect that defaulting to 64 bit integers will hurt performance. Even a single add would be at least two instructions (I'm hoping llvm legalizes a 64 add into 32 add + adc) and you would lose half your registers. Mostly for nothing too since most practical integers fit easily in 32 bits. I think that the native register size is something important enough that it's a waste of time to try to abstract it away. If we're gonna pick a default size for literals then I guess we should pick 32 bits int like C but I'm not sure I like that. |
I'd rather have things work and be slow than not work at all. Most package authors, like you, don't care or ever test with a 32 bit build. |
@tkelman – keep in mind that people may want to run Julia on 32-bit embedded systems. If we changed |
To nitpick C does not pick a specific size. |
In fact, if we're worried about better support for 32-bit, I'd be much more in favor of making it possible to run Julia in 32- and 64-bit modes on both 32- and 64-bit systems. That way you could test packages works with either size of |
There used to be an int literals flag, but I don't think it ever worked. Are you suggesting trying to make fat binaries that include both arches, or just resurrecting and fixing the int literals flag? 64 bit systems can generally download and run 32 bit binaries just fine. Possibly need to install an i386 libc first on linux. BinDeps doesn't support this situation very well though if the system compilers are still 64 bit by default. |
I mean just changing the meaning of |
closed by 209be03 |
Currently we have
Int
which is an alias forInt32
orInt64
depending on the system architecture. I think it would good idea to implement that for floating point numbers as well.The text was updated successfully, but these errors were encountered: