* * *

Author Topic: . operator ?  (Read 2155 times)

sorex

  • New member
  • *
  • Posts: 7
. operator ?
« on: April 04, 2008, 02:13:57 pm »
Hello,

Can anyone tell me what the . (dot) operator was doing in an old TP/BP program or even in freepascal?

like

b:=21167.0;

Phil

  • Hero Member
  • *****
  • Posts: 1338
Re: . operator ?
« Reply #1 on: April 04, 2008, 04:46:04 pm »
Quote from: "sorex"
Hello,

Can anyone tell me what the . (dot) operator was doing in an old TP/BP program or even in freepascal?

like

b:=21167.0;


That's a decimal point, not an operator. Perhaps you're thinking of the string concatenation dot operator in PHP.

Thanks.

-Phil

sorex

  • New member
  • *
  • Posts: 7
RE: Re: . operator ?
« Reply #2 on: April 04, 2008, 11:17:41 pm »
no it's not, when you remove it you'll get totally different results.

when you run this in TP

var N:Integer;
begin
  writeln ('with .');
  for N := 0 to 10 do
  writeln ( Round(Sqr(Sin(N*21167.0))*63));
  writeln;
  writeln ('without .');
  for N := 0 to 10 do
  writeln ( Round(Sqr(Sin(N*21167))*63) );
end.

you'll get

with .
0
47
47
0
48
46
0
49
45
0
49

without .
0
47
60
29
5
19
63
12
2
38
55

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3165
RE: Re: . operator ?
« Reply #3 on: April 05, 2008, 01:33:42 am »
That's probably a problem involving precision and the internal implementation of floating point in TP. I'd recommend you ask at a TP forum, if they still exist.

Anyway, . do is a decimal separator in your code.

It is also indication of access of a function, or variable inside a class, unit or record, but that's in a completely different context.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2626
    • My Lazarus wiki user page
RE: Re: . operator ?
« Reply #4 on: April 05, 2008, 09:53:54 am »
Code: [Select]
21167.0 is a floating point constant,
Code: [Select]
21167 is an integer constant.

Bart

  • Hero Member
  • *****
  • Posts: 794
    • Bart en Mariska's Webstek
RE: Re: . operator ?
« Reply #5 on: April 06, 2008, 09:44:20 am »
And 2*21167 will overflow because it is large then MaxInt (32768 in TP) so you calculate the sinus of a very different angle then with 10*21167.0 (which will not overflow).
Try turning on overflow checking (not sure if TP has this, cannot check it for yu right now) and see what it outputs then (it should cause a runtime error, I guess).

Bart

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads