So the other question is:
Are there any plans to implement these at some point?
On May 26, 8:42 pm, Daniel Smith <dan...@lukenine45.net> wrote:
Kind Regards,
Bjorn.
On May 26, 3:48 pm, Gabor <g...@szfki.hu> wrote:
> a native math function with float64 arguments
> will always be slower than a math function with float32 arguments.
[citation needed]
On 32-bit systems, they are. But I'm not sure about 64-bit systems.
Go runs on x86-32, x86-64, and ARM. Most ARM chips don't
even have floating point, and the x86-32 and x86-64 have no
distinct 32-bit intrinsic instructions. The only way I can see to
get a 32-bit sin, cos, or sqrt would be to change the floating point
register precision with a mode flip. The cost of that mode flip
would more than dwarf any speedup that could be gained from
doing a less precise computation.
Russ
Oh right. I forgot this is about floating point, not integers. Mea
culpa.
> Go runs on x86-32, x86-64, and ARM. Most ARM chips don't
> even have floating point, and the x86-32 and x86-64 have no
> distinct 32-bit intrinsic instructions. The only way I can see to
> get a 32-bit sin, cos, or sqrt would be to change the floating point
> register precision with a mode flip. The cost of that mode flip
> would more than dwarf any speedup that could be gained from
> doing a less precise computation.
Thanks for your answer, I did not know this.
Maybe I remember incorrectly, so I have to test again the anticipated
speedup when switching from 8-byte to 4-byte floating point numbers.
My first question remains:
With the present math package that expects float64 arguments
is there a way to use the elegant x := 2.0 style variable assignments
without declaring var x float64 or use explicit float64(2.0)
conversions.
> My first question remains:
> With the present math package that expects float64 arguments
> is there a way to use the elegant x := 2.0 style variable assignments
> without declaring var x float64 or use explicit float64(2.0)
> conversions.
Pretty sure the answer is no.
In sympathy, I do agree it's awkward that this particular default in
short declarations is not well supported by the math package. I'm
optimistic, though, that this will be resolved by the addition of some
sort of generics at some point, that would allow people to work more
easily in whatever type they choose, for whatever reasons.
In support of the current language and libraries, I'm okay with the
way things are. If an early library is going to support one type
well, it has to float64. As long as all the conversions are in place,
it's enough. The short declarations are controversial, if you review
the posts and issues. I like them, but I think of them as a way to
save typing for some common situations, and not as something that
"should work" in all cases. They have default behavior, and like
defaults in anything, kind of by definition, if you don't want the
default, you must specify otherwise. I'm okay writing,
var x float64 = 2
(and actually happy I don't have to say 2., 2.0, 2d0, etc.)
they could make the default float64 and remove float
without harming anyone particularly.
> i was slightly surprised the language provides "float" at all.
> almost nothing uses it.
>
> they could make the default float64 and remove float
> without harming anyone particularly.
I think that is worth considering.
The only real downside I can see is that there are a few processors
which only natively support 32-bit floating point operations. Of
course Go doesn't currently work on those processors, and it may not
be worth worrying about.
Ian
As a plain user (not a computer scientist) I did not
and do not dare to suggest to get rid of the numeric type float.
But it is obvious that the number type float and the
math package with float64 arguments do not match well.
As for the efficiency of math functions with float64 vs float32
arguments I still do not see clearly, and would greatly appreciate
further comments from the developers.
Using Intel Core 2 duo processors with 32 or 64 bit operating systems
Fortran math functions or the famous FFTW library written in C
always give me a factor of 2 speedup when I switch
from 8-byte to 4-byte floating point numbers.
I still do not understand why this could not be acheived
for the language Go at some point. Not now, but at some point.
On May 27, 7:33 pm, Ian Lance Taylor <i...@google.com> wrote:
This has nothing to do with the math library.
FFTW isn't calling sin or cos repeatedly.
The win there is the use of packed instructions
that can interpret one or two 64-bit values as
two or four 32-bit values and get twice as much
work done in the same number of instructions.
But that's an assembly-level concern, and
you can hook up extra assembly routines to
Go as easily as you can hook them up to C.
The size of the math library functions does not
affect this.
Russ
> Originally, C89 had only math functions with double arguments.
> C99 added two new versions, one for float and one for long double.
> For me this tells that speed and accuracy are also library issues.
> I am totally confused.
There are indeed processors for which 32-bit floating point operations
are faster than 64-bit floating point operations. There are even
processors which implement 32-bit operations in hardware but implement
64-bit operations in software. The Go math library is not optimal for
those processors. But then, the Go compilers don't support them
either.
Ian
Michael T. Jones
Chief Technology Advocate, Google Inc.
1600 Amphitheatre Parkway, Mountain View, California 94043
Email: m...@google.com Mobile: 650-335-5765 Fax: 650-649-1938
Organizing the world's information to make it universally accessible and useful