Mysterious Range Check Error... Help plz!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Mysterious Range Check Error... Help plz!!!

blackr12345blackr12345 Posts: 4Member
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.

[code]program abc;

uses math;

var x: integer;


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



  • quikcarlxquikcarlx Hollywood, FlPosts: 26Member
    It's not that mysterious if you read the definition for the [color=Green]trunc[/color] function and what it returns. I took things by step to see where the [color=Red]Range Check Error[/color] is coming from. And when I changed the definition of x to [color=Green]int64[/color], it worked! Here's what I did to find the error.
    [code]program abc;

    uses math;

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

    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 );

  • blackr12345blackr12345 Posts: 4Member
    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 :(
Sign In or Register to comment.