Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!sun-barr!cs.utexas.edu!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond!diamond From: diamond@diamond.csl.sony.junet (Norman Diamond) Newsgroups: comp.lang.pascal Subject: Re: Realint qestion Message-ID: <10254@socslgw.csl.sony.JUNET> Date: 16 May 89 02:41:09 GMT References: <19573@adm.BRL.MIL> <21930@santra.UUCP> <10247@socslgw.csl.sony.JUNET> <4664@freja.diku.dk> Sender: news@csl.sony.JUNET Reply-To: diamond@csl.sony.junet (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 49 In article <21930@santra.UUCP> s32935k@taltta.hut.fi (Carl Torsten Stenholm) wrote: >>>function realint (x: real): real; >>>begin >>> realint := x - (x - trunc (x)); >>>end; >>>Well now the only difference between this function and putting "trunc (x)" >>>directly in the code is that trunc returns an integer (I think). I replied: >>Suppose MAXINT is 2147whatever (about 2 billion), and x is -2.35e+3000 ? In article <4664@freja.diku.dk> damm@freja.diku.dk (Kristian Damm Jensen) writes: >In that case you would REALLY be in trouble since the code contains a >call trunc (x). Oh yeah, sorry. >I that case you can't just use the standard trunc-function since the >restriction on types are much stronger on parameters than on plain assignment. >In an assignment the types just has to be compatible (for the full >description of type compatibility see the Users Manual And Report >p. 159 (3. ed.))- in parameters they have BE the same type. In fact, this is not correct. Realint takes a *value* parameter, and trunc effectively does the same. For a *value* parameter, the actual must be assignment-compatible to the formal, since it really is only a kind of assignment. Full compatibility is only required for *var* parameters. Please read the standard again, shortly before or after the section you cited. There is a minor difference, since trunc *returns* an integer. The integer can be converted back to real automatically, while the result of realint cannot be converted back to integer automatically (it would need a call to -- you guessed it -- trunc). However, the user of realint really wants a real from it, right? So she could just call trunc instead of realint. He doesn't need realint. In the C group a while back, there were discussions of SLMs (silly little macros). I guess realint might be this group's first SLF. Doubtless there will be more SLFs and SLPs to follow. -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.co.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-implementing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?