On Mon, Feb 4, 2019 at 5:34 AM Miki Tebeka <miki.teb...@gmail.com> wrote:
> A bit of profiling shows that the modulo operator takes most of the time:

C's modulo operator is faster, but can crash if you look at it funny.

$ cat x.c
#include <stdio.h>

int main(int argc, char** argv) {
  int x = -2147483648;
  int y = -1;
  printf("x=%d\n", x);
  printf("y=%d\n", y);
  printf("m=%d\n", x % y);
  return 0;
}
$ gcc x.c && ./a.out
x=-2147483648
y=-1
Floating point exception

Compare it to the output of https://play.golang.org/p/Yj2RZmB7ZRI

Yes, both the Go code and the C code will panic if y is zero. Still,
"-2147483648 % -1" has a sensible mathematical definition (zero), and
C fails to calculate it.

-- 
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.

Reply via email to