delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/18/19:15:06

From: gpt20 AT thor DOT cam DOT ac DOT uk (G.P. Tootell)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: modulus operation with floats requires emulator?
Date: 18 Jan 1997 20:47:39 GMT
Organization: University of Cambridge, England
Lines: 42
Sender: gpt20 AT hammer DOT thor DOT cam DOT ac DOT uk (G.P. Tootell)
Message-ID: <5brctb$dap@lyra.csx.cam.ac.uk>
References: <5br7o7$p2e AT news1 DOT panix DOT com>
NNTP-Posting-Host: hammer.thor.cam.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

well it's right, they are invalid operands :) you can't use % to modulus floating
point numbers. there may be a function in the math.h library that lets you do
modulus but i don't know it offhand sorry. you could try looking at math.h
however

regards,
nik.

In article <5br7o7$p2e AT news1 DOT panix DOT com>, awnbreel AT panix DOT com (Michael R Weholt) writes:
|>         I'm using Win95 on a pentium.  Norton Utilities reports that 
|> "Math Support is on chip".
|> 
|>         When I try to use the modulus operation, I can only get it to 
|> work using integers, not floats.  When I try it with floats, the 
|> debugger reports: "Error: invalid operands to binary %".  I get this 
|> message even when I try including math.h, or adding the -lm link 
|> option.
|> 
|>         Does this mean I have to get the 387 emulator and use it?
|> 
|>         I'm just learning C, so I suppose I could have something wrong 
|> with the source.  The following gets the debug message described 
|> above:
|> 
|> #include <stdio.h>
|> #include <math.h>
|> 
|> float   mod;
|> 
|> main()
|> {
|>     mod = 9.0 % 5.0;
|> 
|>     (void) printf("modulus: %f\n", mod);
|>     return(0);
|> }
|> 
|> Michael R Weholt
|>  http://www.panix.com/~mrw/
|> 

-- 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019