English Amiga Board Amiga Lore


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 07 June 2014, 17:09   #1
Raislin77it
Zone Friend
Raislin77it's Avatar
 
Join Date: Jan 2005
Location: italy
Age: 40
Posts: 217
BLITZ BASIC 2 "floor,ceiling and modulo% equivalent"

hi, there are this operators in blitz basic 2 ?

floor ?
ceiling ?
modulo "%" ?

i cannot find in the manual unfortunately
Raislin77it is offline  
AdSense AdSense  
Old 07 June 2014, 23:49   #2
leathered
Registered User

leathered's Avatar
 
Join Date: Oct 2011
Location: UK
Age: 40
Posts: 304
I don't think you'll find anything specifically to that effect but the manual is here: http://coagulus.newport.net/t/b.pdf
If you're looking to do something 'Doomy' you might have some luck with a C2P library, Mildred is one of them. I've never used it, so can't say what it's like but there were some good examples made with one of the C2P libraries on the Blitz BUM's.
leathered is offline  
Old 08 June 2014, 07:39   #3
Ze Emulatron
Registered User

 
Join Date: Nov 2010
Location: Otorohanga, New Zealand
Posts: 174
From Blitz Basic 2 - Reference Guide-ENG.pdf available on http://amiga-manuals.xiik.net/amiga.php in eBooks category Blitz_Basic_2___ebook_ENG.rar -> 37328 KB

For floor

Function: Int
Syntax: Int (Expression)
Modes: Amiga/Blitz
Description:
This returns the Integer part (before the decimal point) of Expression.
Example:
Code:
Print Int(23.456) ; Will simply print 23

Mod
Code:
Print 10 MOD 3 ; Will print 1
For Ceiling you could do
Code:
PRINT (INT(23.456))+1

If you really want to use ceiling and floor you could do

Code:
function ceiling{n}
  function return (INT(n))+1
end function
Code:
function floor{n}
  function return INT(n)
end function

Last edited by Ze Emulatron; 08 June 2014 at 07:45.
Ze Emulatron is offline  
Old 08 June 2014, 10:30   #4
Raislin77it
Zone Friend
Raislin77it's Avatar
 
Join Date: Jan 2005
Location: italy
Age: 40
Posts: 217
Quote:
Originally Posted by Ze Emulatron View Post
From Blitz Basic 2 - Reference Guide-ENG.pdf available on http://amiga-manuals.xiik.net/amiga.php in eBooks category Blitz_Basic_2___ebook_ENG.rar -> 37328 KB

For floor

Function: Int
Syntax: Int (Expression)
Modes: Amiga/Blitz
Description:
This returns the Integer part (before the decimal point) of Expression.
Example:
Code:
Print Int(23.456) ; Will simply print 23
Mod
Code:
Print 10 MOD 3 ; Will print 1
For Ceiling you could do
Code:
PRINT (INT(23.456))+1
If you really want to use ceiling and floor you could do

Code:
function ceiling{n}
  function return (INT(n))+1
end function
Code:
function floor{n}
  function return INT(n)
end function
thanks a lot, Ze Emulatron i have skipped the INT and MOD commands
(and thanks leathered for the sprite trick in the other thread )
Raislin77it is offline  
Old 08 June 2014, 11:26   #5
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,507
Quote:
Originally Posted by Ze Emulatron View Post
If you really want to use ceiling and floor you could do

Code:
function ceiling{n}
  function return (INT(n))+1
end function
Code:
function floor{n}
  function return INT(n)
end function
It's a bit more complicated than that.

These should do:

Code:
function ceiling{n}
  i = abs(int(n))
  f = abs(n) - i

  if f = 0 then
    return n
  endif

  if n < 0 then
     return -i
  else
     return i + 1
  endif
end function

Code:
function floor{n}
  i = abs(int(n))
  f = abs(n) - i

  if f = 0 then
    return n
  endif

  if n < 0 then
     return -i - 1
  else
     return i
  endif
end function
(Note that I never used (Blitz) Basic. I just adopted your syntax. So the actual syntax might need to be different.)
thomas is offline  
Old 08 June 2014, 13:23   #6
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,507
Your ceiling example doesn't work for whole numbers, either.
thomas is offline  
Old 08 June 2014, 18:43   #7
Ze Emulatron
Registered User

 
Join Date: Nov 2010
Location: Otorohanga, New Zealand
Posts: 174
Quote:
Originally Posted by thomas View Post
It's a bit more complicated than that.

These should do:

Code:
function ceiling{n}
  i = abs(int(n))
  f = abs(n) - i

  if f = 0 then
    return n
  endif

  if n < 0 then
     return -i
  else
     return i + 1
  endif
end function

Code:
function floor{n}
  i = abs(int(n))
  f = abs(n) - i

  if f = 0 then
    return n
  endif

  if n < 0 then
     return -i - 1
  else
     return i
  endif
end function
(Note that I never used (Blitz) Basic. I just adopted your syntax. So the actual syntax might need to be different.)
Those seem to work fine when adapted to Blitz, I didn't get around to testing whole numbers or negative numbers when I wrote mine, I couldn't remember what way floor and ceil worked with negatives off the top of my head and I didn't have an environment to test them in.

Quote:
Originally Posted by thomas View Post
Your ceiling example doesn't work for whole numbers, either.
I adapted my code to fix those issues, I think I copied the new code correctly. Sorry about the caps, I write reserved keywords in BASIC languages in caps since using amiga basic.

Code:
FUNCTION ceiling{n}
  IF SGN(n) = 1 AND FRAC(n) <> 0
    FUNCTION RETURN (INT(n))+1
  END IF
  FUNCTION RETURN (INT(n))
END FUNCTION
Code:
FUNCTION floor{n}
  IF SGN(n) = -1 AND FRAC(n) <> 0
    FUNCTION RETURN (INT(n))-1
  END IF
  FUNCTION RETURN (INT(n))
END FUNCTION

Last edited by Ze Emulatron; 08 June 2014 at 19:00.
Ze Emulatron is offline  
Old 24 March 2015, 15:42   #8
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 2,975
I think the ceiling function is accomplished using QWrap().
idrougge is offline  
Old 26 March 2015, 21:34   #9
Cylon
Registered User

 
Join Date: Oct 2014
Location: Europe
Posts: 447
Quote:
Originally Posted by idrougge View Post
I think the ceiling function is accomplished using QWrap().
No, QWrap(in,min,max) does:

IF in => max THEN in=min

As in :

Code:
While NOT(JoyB(0))
   a=QWrap (a+1,1,20)
   Print a," "
   VWait 25
Wend

End
Will output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 2 3 4 5 ...

Furthermore, the difference in-max is added to min, if in exceeds max:

Code:
NPrint QWrap(35,1,20)
MouseWait
> 16

Last edited by Cylon; 28 March 2015 at 01:21. Reason: good.
Cylon is offline  
Old 15 July 2015, 17:57   #10
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 2,044
Again, just adding to this slightly old thread with another option: Use QLimit() instead of QWrap() - you give that min and max values and it gives the min value if the input is lower than the min, and the max value if the input is higher than the max. Bear in mind it only works on quick type variables so feeding it longs might give you strange results.

Also, for the modulo function there is Frac() which returns the fractional part of a number. QFrac() can be used if the input is a quick type, and will execute quicker.

A full version of the original Blitz Basic 2.1 manual is available here: http://www.amiblitz.de/content/blitz...mers/0001.html
Daedalus is offline  
Old 19 July 2015, 05:24   #11
Cylon
Registered User

 
Join Date: Oct 2014
Location: Europe
Posts: 447
Thanks, but the whole QWrap()/QLimit() stuff is useless if you want to use faster calculations. You have to write your own WWrap()/LWrap()/LLimit() funcs and so on.
Quick types suck for advanced coding. They are nice for beginners but slow down the real sh*t.
Cylon is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Doom port where you can switch off floor and ceiling rendering vroom6sri support.Games 5 11 February 2014 09:38
"DIR" equivalent to "ls |more" Gaula92 Coders. System 5 22 September 2013 21:53
"Reminder "Lincs Amiga User Group aka "LAG" Meet Sat 5th of January 2013" rockape News 4 30 January 2013 00:06
CD32 Image-Name-Bug: "...(bla)[!].zip" -> "...(bla)[" / "...[test].zip" -> "...[tes" cfTrio support.WinUAE 8 18 December 2012 16:31
Can I access cf/sd-pcmcia with a "basic" WB3.0 floppy? emuola New to Emulation or Amiga scene 7 12 August 2009 07:09

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:50.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.28698 seconds with 12 queries