Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-12

Sin function

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

faber

Hi,
according to docs/reference sin function should print 0.0 when

Writeln (Sin(Pi):0:1);

but, with fpc 2.4.0 and 2.4.2 (x86) I've get "-0.0", such a result is not entirely correct.
This is a bug (in sin func.) or something wrong with the formatting ?

best regards
faber

Reply by email

Ingemar Ragnemalm
faber wrote 12 lines
Hi, according to docs/reference sin function should print 0.0 when Writeln (Sin(Pi):0:1); but, with fpc 2.4.0 and 2.4.2 (x86) I've get "-0.0", such a result is not entirely correct. This is a bug (in sin func.) or something wrong with the formatting ? best regards faber

If I were you I would print it with more digits so you see if there is any significant difference at all.

/Ingemar

Reply by email

faber
to Ingemar Ragnemalm
If I were you I would print it with more digits so you see if there is any significant I understand, I was suggested by
http://www.freepascal.org/docs-html/rtl/system/sin.html where it is
given score 0.0 for Writeln (Sin(Pi):0:1);

best regards
faber

Reply by email

Ivo Steinmann
to Ingemar Ragnemalm: If I were you I would print it with more digits so you see if there is any significant…

Hi Ingemar

0.0 and -0.0 is the same number ;) it's just a quirk of the IEEE floating point format, that there exists a positiv and negative zero (because they use a sign bit).

-Ivo

Ingemar Ragnemalm wrote 24 lines
faber wrote: > Hi, > according to docs/reference sin function should print 0.0 when > > Writeln (Sin(Pi):0:1); > > but, with fpc 2.4.0 and 2.4.2 (x86) I've get "-0.0", such a result is > not entirely correct. > This is a bug (in sin func.) or something wrong with the formatting ? > > best regards > faber If I were you I would print it with more digits so you see if there is any significant difference at all. /Ingemar _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Mark Morgan Lloyd
to faber: http://www.freepascal.org/docs-html/rtl/system/sin.html where it is given score 0.0 for…
faber wrote 6 lines
> If I were you I would print it with more digits so you see if there is any > significant difference at all. ok I understand, I was suggested by http://www.freepascal.org/docs-html/rtl/system/sin.html where it is given score 0.0 for Writeln (Sin(Pi):0:1);

Transcendentals are a can of worms. Without and with formatting respectively,

ARM, PowerPC, SPARC:

1.22464706384516E-016
0.0

x86 (P-III):

-5.4210108624275222E-0020
-0.0

All FPC 2.4.2 on Linux. The result /should/ be zero, and x86- which I presume is what you're running- is nearer zero than the others :-)

There are lots of issues here, including the number of bits used internally by the floating point hardware and whether it knows Pi to this degree of precision. Also it might depend on optimisation level etc.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Lukasz Sokol
to faber: according to docs/reference sin function should print 0.0 when Writeln (Sin(Pi):0:1);…

Hi faber,

well, even mathematically, it is sorta right... yes the sin(0)=0 but looking at its graph, it is a rising slope, so sin(x near to 0-) < 0 :)

:)
L.

faber wrote 15 lines
Hi, according to docs/reference sin function should print 0.0 when Writeln (Sin(Pi):0:1); but, with fpc 2.4.0 and 2.4.2 (x86) I've get "-0.0", such a result is not entirely correct. This is a bug (in sin func.) or something wrong with the formatting ? best regards faber _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email