After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 610660 - modulo operator (%) error
modulo operator (%) error
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Basic Types
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-02-22 07:03 UTC by Nor Jaidi Tuah
Modified: 2010-03-19 18:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
use fmod and fmodf (1.47 KB, patch)
2010-03-11 11:12 UTC, Luca Bruno
none Details | Review
Test case which fails after the patch to this bug is applied (93 bytes, application/octet-stream)
2010-03-19 18:34 UTC, Evan Nemerson
  Details

Description Nor Jaidi Tuah 2010-02-22 07:03:51 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
Comment 1 Luca Bruno 2010-03-10 22:07:35 UTC
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.
Comment 2 Luca Bruno 2010-03-11 11:12:31 UTC
Created attachment 155838 [details] [review]
use fmod and fmodf
Comment 3 Jürg Billeter 2010-03-19 17:29:14 UTC
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.
Comment 4 Evan Nemerson 2010-03-19 18:34:25 UTC
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).