Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Mysterious Range Check Error... Help plz!!! Posted by blackr12345 on 21 Oct 2012 at 11:46 AM
I dry ran these codes for hours but I couldn't find a solution to the Range Check Error.

The compiler I am using is FreePascal 2.6.

Please help. Thank you in advance.

program abc;

uses math;

var x: integer;

begin

x:= trunc(power(10, 2/log10(2)));

readln
end.

Report
Re: Mysterious Range Check Error... Help plz!!! Posted by quikcarlx on 22 Oct 2012 at 6:10 PM
It's not that mysterious if you read the definition for the trunc function and what it returns. I took things by step to see where the Range Check Error is coming from. And when I changed the definition of x to int64, it worked! Here's what I did to find the error.
program abc;

  uses math;

  var
    x : int64;
    lv : float;
    pv : float;
    tv : float;

begin
  lv := 2 / log10( 2 );
  pv := power( 10, lv );
  tv := trunc( pv );
  writeln( lv:12:6,'  ', pv:12:6, '  ', tv:12:6 );

  x := trunc(power(10, 2/log10(2)));
  writeln( x:12 );

  readln
end.

Report
Re: Mysterious Range Check Error... Help plz!!! Posted by blackr12345 on 13 Nov 2012 at 11:48 PM
Thank you so much!!!
Choosing the correct data type is so hard for me~

btw, sorry for my late reply which is due to a login problem :(



 

Recent Jobs