On Fri, Aug 4, 2017 at 9:24 AM, <djad...@gmail.com> wrote: > Ok, > i'm not right,pow in C is : > float powf(float x, float y); > long double powl(long double > > use float32 pow for proper comparison or use powl for C double wersion. >
C'pow is with doubles (like Go's math.Pow): https://linux.die.net/man/3/pow ``` Synopsis #include <math.h> double pow(double x, double y); ``` -s > This is demonstartion how when you use go long time, you lose ability to > read other languages :) > > > On Friday, August 4, 2017 at 10:15:06 AM UTC+3, dja...@gmail.com wrote: >> >> You are comparing apples to oranges( integer vs float64 pow), >> use integer pow and compare again: >> >> >> func Pow(a, b int) int { >> p := 1 >> for b > 0 { >> if b&1 != 0 { >> p *= a >> } >> b >>= 1 >> a *= a >> } >> return p >> } >> >> >> On Friday, August 4, 2017 at 9:20:41 AM UTC+3, Dorival Pedroso wrote: >>> >>> I've noticed that this C code: >>> >>> #include "math.h" >>> int main() { >>> double x = 2.5; >>> int Nmax = 10000000; >>> for (int N=0; N<Nmax; N++) { >>> for (int i=0; i<20; i++) { >>> pow(x, i); >>> } >>> } >>> } >>> >>> can run up to 50x faster than this Go code: >>> >>> package main >>> >>> import "math" >>> >>> func main() { >>> x := 2.5 >>> Nmax := 10000000 >>> for N := 0; N < Nmax; N++ { >>> for i := 0; i < 20; i++ { >>> math.Pow(x, float64(i)) >>> } >>> } >>> } >>> >>> The C code was compiled with: gcc -O2 ccode.c -o ccode -lm >>> then run with time ./ccode >>> >>> The Go code was compiled with: go build gcode.go >>> then run with time ./gcode >>> >>> I've used the time command on Linux (Ubuntu) to get some estimate. >>> >>> So the question is: how can we make the Go code faster? >>> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.