Sign in Join

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

Mailing lists / fpc-pascal / 2016-06

default parameter single = NaN

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

David Emerson

Hey all,

After installing fpc 3.0.0, I'm getting an...

Error: function header doesn't match the previous declaration

for a (non-method) function that does exactly match its previous declaration:

function make_scale_matrix (zx:single; zy:single=NaN):t_2d_affine;

I use "NaN" extensively to indicate a null / not specified value, so it would really be a drag to lose this feature. Although the header exactly matches the previous declaration, it now objects to these NaN default parameters.

Aside from the error message being misleading/inaccurate, I didn't notice any mention of this in the user changes document; nor is this prohibition mentioned in the html documentation online, http://wiki.freepascal.org/Default_parameter

What's the status of this?

Given this feature loss, I would have to either abandon the default parameter feature and create many similar functions; or, pick another value to use (when NaN is ideal).

Thanks,
~David

Reply by email

Jonas Maebe
to David Emerson
David Emerson wrote 11 lines
Error: function header doesn't match the previous declaration for a (non-method) function that does exactly match its previous declaration: function make_scale_matrix (zx:single; zy:single=NaN):t_2d_affine; I use "NaN" extensively to indicate a null / not specified value, so it would really be a drag to lose this feature. Although the header exactly matches the previous declaration, it now objects to these NaN default parameters.

It's probably due to a peciularity of the "NaN" value itself: if you ask a floating point unit to compare NaN with NaN, the returned result must always be "not equal" even though the bit patterns match exactly. To fix this, the compiler will have to compare the bit patterns of floating point default parameters rather than their values as floating point numbers.

Please file a bug report.

Jonas

Reply by email

Martin
to David Emerson
David Emerson wrote
I found a workaround, which is to use Infinity as the default value, instead of NaN. It's acceptable for my use, though a little awkward.

there is another workaround.

Do not repeat the default  as
   function make_scale_matrix (zx:single; zy:single=NaN):t_2d_affine;
But implement as
   function make_scale_matrix (zx:single; zy:single):t_2d_affine;
   begin
   end;

Reply by email

David Emerson
to Jonas Maebe: It's probably due to a peciularity of the "NaN" value itself: if you ask a floating point…
Jonas Maebe wrote 19 lines
On 20/06/16 22:59, David Emerson wrote: > Error: function header doesn't match the previous declaration > > for a (non-method) function that does exactly match its previous > declaration: > > function make_scale_matrix (zx:single; zy:single=NaN):t_2d_affine; It's probably due to a peciularity of the "NaN" value itself: if you ask a floating point unit to compare NaN with NaN, the returned result must always be "not equal" even though the bit patterns match exactly. To fix this, the compiler will have to compare the bit patterns of floating point default parameters rather than their values as floating point numbers. Please file a bug report. Jonas

filed

~David

Reply by email

David Emerson
to Martin: there is another workaround. Do not repeat the default as function make_scale_matrix…
Martin wrote 14 lines
On 20/06/2016 22:45, David Emerson wrote: > I found a workaround, which is to use Infinity as the default value, > instead of NaN. It's acceptable for my use, though a little awkward. there is another workaround. Do not repeat the default value at implementation. Declare as function make_scale_matrix (zx:single; zy:single=NaN):t_2d_affine; But implement as function make_scale_matrix (zx:single; zy:single):t_2d_affine; begin end;

Thanks, Martin! This is much better.

Reply by email