GNOME Bugzilla – Bug 610660
modulo operator (%) error
Last modified: 2010-03-19 18:34:25 UTC
vala version: 0.7.10 Expression such as angle % Math.PI is accepted by the compiler but produces invalid c with this message: "invalid operands to binary % (have ‘double’ and ‘double’)" The above expression do in fact make sense and I hope this is an intended feature of vala. So, this should be a bug in the code generator rather than the type checker. hand
Should we allow % to be used only for integers so that the user must use fmod and fmodf or call the function implicitly? I'd say let's do this implicitly if they're two doubles or two floats. If types are different report the error.
Created attachment 155838 [details] [review] use fmod and fmodf
commit 1b358f3e4da2c59af2b7757db686935a37738a16 Author: Luca Bruno <lethalman88@gmail.com> Date: Thu Mar 11 12:10:03 2010 +0100 Use fmod/fmodf for modulo operation between floating point values Fixes bug 610660.
Created attachment 156574 [details] Test case which fails after the patch to this bug is applied fmod and fmodf are in libm, which will not be used unless explicitly requested (-X -lm) by the user. This is annoying for the math functions in the glib and posix vapis, but forcing it on people who just do foo % bar is cruel. Florian Brosch and I were talking about the -lm situation for the vapis a few days ago, and he had the idea to automatically add -lm when math.h was included--I can't think of a reason not to do that, and it would solve both issues nicely. The attached test case works with -X -lm, but fails without it (on Debian sid at least).