Results 1 to 8 of 8

Thread: is there a function whole or not

  1. #1
    Join Date
    Jun 2007
    Posts
    246
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default is there a function whole or not

    is there a function to check if a number is whole or not? i tried using
    SCAR Code:
    function Iswhole(i: extended): Boolean;
    begin
      Result:= ((i mod 1) = 0);
    end;
    but that doesnt work cuz i guess mod only works with integers =/

  2. #2
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well... I have here a func to make a # whole. Here it is:
    SCAR Code:
    Function MakeWhole(number:Extended):Integer;
      Var
        i:String;
      Begin
        i:=FloatToStr(Trunc(number));//make trunc to round to round the # rather than truncate it.
        Result:=StrToInt(i);
      End;

    Begin //how to test
      Writeln(IntToStr(MakeWhole(7.3)));
    End.

    Leme try to get a IsWhole func, one sec.

    EDIT: Got one!!!
    SCAR Code:
    Function IsWhole(number:Extended):Boolean;
      Var
        q:Extended;
      Begin
        Result:=False;
        q:=Trunc(number);
        If (q=number) Then
        Begin
          Result:=True;
          Exit;
        End;
      End;

    Begin //how to test
      Writeln('Is 7.4 whole? ' +BoolToStr(IsWhole(7.4)));
      Writeln('Is 7 whole? ' +BoolToStr(IsWhole(7)));
    End.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  3. #3
    Join Date
    Jun 2007
    Posts
    246
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    woot thanks haha thats a nice way to see if its whole..round it down then see if it equals original number =) i just learned what trunc does. that is what it does right?

  4. #4
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, trunc just slices off the decimal parts. (castrates a float lmao)
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  5. #5
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Shorter:
    SCAR Code:
    function IsWhole(e: Extended): Boolean;
    begin
      Result:= StrToFloat(IntToStr(Trunc(e))) = e;
    end;
    Sorry, couldn't help myself

  6. #6
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    DAMN YOU TO HELL BULZEYE!!!!
    I'm jk, nice consolidation.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  7. #7
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function IsWhole(e: Extended): Boolean;
    begin
      Result:= 1.0*Trunc(e) = e;
    end;
    No strings attached.

  8. #8
    Join Date
    Jun 2007
    Location
    Minnesota
    Posts
    773
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Boreas View Post
    SCAR Code:
    function IsWhole(e: Extended): Boolean;
    begin
      Result:= 1.0*Trunc(e) = e;
    end;
    No strings attached.
    PWNT

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 02-27-2008, 05:20 PM
  2. Replies: 2
    Last Post: 02-26-2008, 08:26 PM
  3. Any function that does this?
    By shadowpwner in forum OSR Help
    Replies: 2
    Last Post: 08-14-2007, 03:15 AM
  4. [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]
    By ZephyrsFury in forum Research & Development Lounge
    Replies: 10
    Last Post: 07-27-2007, 08:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •