Board index » delphi » Turbo Pascal and Reals and Integers
SILFVAS
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT

SILFVAS
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Turbo Pascal and Reals and IntegersQuoteJonas Sandman wrote: r : real; i := trunc(r); I think these should work for you. 
Jonas Sandma
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersI use Turbo Pascal 7.0 for DOS in school and I wonder if you can convert a If you know how, mail me! Jonas Sandman 
Frank Peel
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersJonas Sandman <jonas.sand...@mail.bip.net> wrote in article Quote> I use Turbo Pascal 7.0 for DOS in school and I wonder if you can convert real to the nearest integer, up or down. Round(1.5) = 2 Frank 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersIn article <01bcefa2$ff12e4e0$1ea8edc2@foo>, QuoteJonas Sandman <jonas.sand...@mail.bip.net> wrote: errors is very user friendly. Assigning a real to an integer is can cause loss of accuracy and even an error. Therefore it is good that the user has to specify exactly how the value is modified (rounding or truncating, round() or trunc()). On the other hand assigning integers to reals have no problems. (OK, exception, if you assign longint into a single you can loose accuracy as single has only 23 bits (+sign) for mantissa. Real on the other hand has 39 bits so it can store any longint accurately.) Osmo 
Ephram Cohe
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuoteFrank Peelo wrote: Quote> Trunc will round the real down to the nearest integer. Round will round the In the following code we get printed out This happens for single and double also. I have read in this group that My substitue function is I chose 0.49999 kindowillynilly. I have no real reason for that many Quote> Frank Programmer Auditory Lab UC Berkeley 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersIn article <346CA276.AC611...@ear.berkeley.edu>, Quote
2 Try running it with $N. Quote
Quote>My substitue function is Function integ( value : single):integer; Osmo 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersIn article <346DF975.59436...@ear.berkeley.edu>, Quote>Osmo Ronkanen wrote: point routines. The fact that you used Reals implied that. Btw why on earth would you use reals with coprocessor? On earlier processors that could be slower than using $N. Also using reals with $N has nothing whatsoever to do with any Quote
coprocessor so emulation is the only way that I can do fpoperations when I have $N+. I verified your results with emulation. Again calculating floating point with software is not necessarily emulation. Quote
0.4999999999. Also one can understand more easily why it works. If you want to include a branch then sure you can do that: Function integ( value : single):integer; My point was to get rid of the 0.49999999, not with the branch. Quote>I happen to like the readability of mine. the fact that your code does not work with emulation. I got 1 when I tried integ(1.5). Now with emulation I really mean emulation. Quote>Anyone care to comment on the runtime for each? I suppose I could 
Ephram Cohe
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuoteOsmo Ronkanen wrote: as real. [...] Quote> Also using reals with $N has nothing whatsoever to do with any point options 1) $N "software runtime library" real type only In my admitedly simple tests I found that option 2 and 3 behaved the [...] Quote> >there are different emulation v hardware that I said here. [...] Quote> IMO the big benefit is that one does not have to choose any ugly Quote> Also there is the positive" for .5 values :). What is defined in the pascal doc's is rounds "away from zero" for the .5 cases. Since I was "fixing" round I decided to do it "towards the positive". It makes sense for the types of things that I do at work. The original point that I was trying to make was I was mainly trying to make the original poster aware of this Quote> >> Osmo 
Horst Kraem
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersOn 13 Nov 1997 00:34:29 GMT, "Frank Peelo" <fpe...@indigo.ie> wrote: Quote>Trunc will round the real down to the nearest integer. Round will round the Round(2.5) = 3 Quote> Trunc(1.5) = 1 If the fractional part is exactly 0.5, the behaviour depends on the {$N+} This is one of the reasons why you should never use REAL and $N+. Look at this one. {$N+} This is a {*word*193} inconsistency (which I would call a bug) in all TP The problem is that the roundinstruction for c25 in the first This only a marginal problem, of course. Everybody who relies on a Regards 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersIn article <346F41AB.22826...@ear.berkeley.edu>, Quote>Osmo Ronkanen wrote: emulation is only used when there is a no coprocessor. $N+,E+ is so that one can produce programs that run fast on coprocessor but also run on computers without one. If you want to test the actual emulation you have to fool the program to think there is no coprocessor. This is done with "SET 87=N" at the prompt. Note it is bad to use reals when one uses $N+, especially with $E+. ... Quote
really is a problem then maybe you should consider some other data type. The nature of reals (in mathematical chance) is that if one picks a random one the probability that the fraction is exactly 0.5 is zero. If that really causes a major problem then maybe you should consider some other data type. Especially if you are playing with money, do not use reals with pennies as fractions. Osmo 
Ephram Cohe
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuote> Note it is bad to use reals In my book it is bad to use reals, ever. The nature of the work that I var s:single; Quote
problematic. Someone _may_ care what kind of error is being introduced by round. The round towards even introduces a "frequency modulation" error. It has mean error of 0. That is one type. The round away from 0 (your code using .5 for the negative fixup value) The round toward the positive introduces a small DC error but reduces Quote>Btw if that who had some questions about round. Quote> The nature of reals (in mathematical chance) is that if one picks a represents a range of values that is a function of the number of bits used to represent that type. Since the value .5 actually represents a range. It has an area in the distribution of real numbers. This yields a nonzero chance of a .5 occurring. If you were using round(random(n)) to get integer values you would end Quote>Especially if you are playing with money, do not use Quote> Osmo 
Ephram Cohe
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuoteOsmo Ronkanen wrote: [description of the types of round deleted] Quote> Maybe you should have said these in your first message and not assumed produces inconsistent results. It was not a discussion of why one might care that they are inconsistent, the fact that they are should be enough for people to take some notice. as Horst Kraemer said in this thread Quote>This is a {*word*193} inconsistency (which I would call a bug) in all TP Quote> In Mathematics there are no bits. action in a digital computer programmed in Borland(tm) Pascal, where there are bits. Quote> Now computer reals little knowledge. I saw that the round towards even was a problem and I fixed it for my own code (a correct data type now?). The round towards even seemd to me to be particularly egregious so I made mention of it. Quote> Are slot machines based on pseudo random numbers legal? and b) The point really is if you use round(random*n) you do not end up with a uniform distribution. There will be a slight bias towards even #'s Quote> I'd use trunc() if I'd ever use reals. Quote

CBongCh
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuote>Subject: Re: Turbo Pascal and Reals and Integers offers only 4 different ways of "rounding": 1. round toward nearest or even (default) Therefore numbers like 2.5 are rounded to the nearest even integer2. AFAIK Quote>What anoys me is that it does not do what is IMO convention for rounding numbers like 2.5 is toward the nearest even integer. I think the idea is either to minimize error (the ".5" numbers give the most error in rounding, which adds up when doing operations with rounded #s unless the "even rule" is used; for example, when rounded mathematically, 2.5+1.5 = 4 becomes 3 + 2 = 5, while the even rounding gives 2 + 2 = 4...) or is just plain convention. And floatingpoints are designed for scientific rather than mathematical purposes. Nevertheless, I must confess that I find this discrepancy between scientific and mathematical rounding to be annoying. Quote>What anoys me more is that there are different <snip>  Hide quoted text   Show quoted text  Quote>> Osmo 
Osmo Ronkan
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersIn article <19971118214101.QAA09...@ladder02.news.aol.com>, QuoteCBongChan <cbongc...@aol.com> wrote: fractions. So if one chooses rounding up, 2.1 becomes 3. Quote
errors in large group of numbers to cancel each out. 0.1 cancels 0.9, 0.2 or 0.8 and so on. To cancel 0.5 out one has to round then up half a time and down half a time. (That was a simplified example, computers work with binaries and with greater accuracy) Osmo 
CBongCh
Delphi Developer 
Wed, 18 Jun 1902 08:00:00 GMT
Re:Turbo Pascal and Reals and IntegersQuote>Subject: Re: Turbo Pascal and Reals and Integers selected via the Rouding Control Field in the Coprocessor Control Word. <snip> 
1. Need help with converting between Reals and integers!
2. Turbo Pascal help needed for integer conversion
3. Help: How does Delphi v2 read files with integer arrays created in Turbo and Borland Pascal
4. Turbo Pascal 7 or Educational Turbo Pascal 7
5. Converting pascal 6byte reals to C 8byte doubles
6. Converting pascal 6byte reals to C 8byte doubles
7. Turbo Power's Turbo Professional and Free Pascal
9. How might I get Turbo Pascal 7.0 and Turbo De{*word*81} 4.6 to play together
10. WTD  Borland/Turbo Pascal Manuals/SW Especially Turbo Vision