Jump to content

ceilling / Array / ubound


jonk
 Share

Recommended Posts

Hi,

I have some simple Questions to the following example:

Why returns ubound($array) in this script "1"? :P

Returns ceilling really an integer? Because, isint($z) returns false? ;)

Could anyone please help me?

Dim $x=4

Dim $y=3

Dim $z = Ceiling($x/$y)

Dim $array[$z]

Dim $array2[$z+1]

MsgBox(0,"","$z= "&$z& "/ ubound array= "&ubound($array) & "/ isint: "&isint($z) & "/ int: "&int($z) &"/ ubound array2= "&ubound($array2))

Link to comment
Share on other sites

  • Developers

Hi,

I have some simple Questions to the following example:

Why returns ubound($array) in this script "1"? :P

Returns ceilling really an integer? Because, isint($z) returns false? ;)

Could anyone please help me?

Looks like a BUG to me... to demo it run this:

#include<math.au3>

Dim $x = 4

Dim $y = 3

Dim $z = Ceiling($x / $y)

Dim $array[$z]Dim $array2[$z + 1]

ConsoleWrite("$z= " & $z & "/ ubound array= " & UBound($array) & "/ isint: " & IsInt($z) & _

"/ int: " & Int($z) & "/ ubound array2= " & UBound($array2) & @LF)

Dim $z = _Ceil($x / $y)

Dim $array[$z]

Dim $array2[$z + 1]

ConsoleWrite("$z= " & $z & "/ ubound array= " & UBound($array) & "/ isint: " & IsInt($z) & _

"/ int: " & Int($z) & "/ ubound array2= " & UBound($array2) & @LF)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This one works correct:

#include<math.au3>

Dim $z = _Ceil($x / $y)

Dim $array[$z]

Dim $array2[$z + 1]

ConsoleWrite("$z= " & $z & "/ ubound array= " & UBound($array) & "/ isint: " & IsInt($z) & _

"/ int: " & Int($z) & "/ ubound array2= " & UBound($array2) & @LF)

output is:

$z= 2/ ubound array= 2/ isint: 1/ int: 2/ ubound array2= 3

Thank you for help, JdeB ;)

Link to comment
Share on other sites

  • Developers

This one works correct:

_ceil() is an undocumented UDF from the math.au3 UDF lib which was replaced with the internal Ceiling() command.

Created a BUG report for Nutster to check Ceil() ... (When he got his PC back in shape ;) )

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

_ceil() is an undocumented UDF from the math.au3 UDF lib which was replaced with the internal Ceiling() command.

Created a BUG report for Nutster to check Ceil() ... (When he got his PC back in shape :P )

... after testing, the UDF _ceil() is not perfect too ;)

if you pass an integer to _ceil() it increments the value by one, but it should not do that.

I modified the UDF like this:

Func _Ceil($nValue)

If (Not IsNumber($nValue)) Then

SetError(1)

Return (0)

EndIf

SetError(0)

if(isint($nValue))then

Return $nValue

Else

Return ( Int($nValue) + 1)

Endif

EndFunc ;==>_Ceil

Link to comment
Share on other sites

  • Developers

;) This is what is strange:

$z = Ceil(3/2) ; $z is equal 2 - is correct

Dim $Array[$z]

Ubound($Array) = 1 - is wrong ... should be 2

Dim $Array[$z+1]

Ubound($Array) = 3 - is correct

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

;) This is what is strange:

$z = Ceil(3/2) ; $z is equal 2 - is correct

Dim $Array[$z]

Ubound($Array) = 1 - is wrong ... should be 2

Dim $Array[$z+1]

Ubound($Array) = 3 - is correct

With the script:

#include <Math.au3>

ConsoleWrite("Version: " & @AutoItVersion & @CR)
Local $z = Ceiling(3/2)
Dim $Array[$z]
ConsoleWrite(Ubound($Array) & @CR)
Dim $Array[$z+1]
ConsoleWrite(Ubound($Array) & @CR)

Local $z = _Ceil(3/2)
Dim $Array[$z]
ConsoleWrite(Ubound($Array) & @CR)
Dim $Array[$z+1]
ConsoleWrite(Ubound($Array) & @CR)

I get:

Version: 3.1.1.75

2

3

2

3

Link to comment
Share on other sites

  • Developers

Work for me correct as well.... but why does this code go wrong then ?

Dim $x = 4
Dim $y = 3
Dim $z = Ceiling($x / $y)
Dim $array[$z]
Dim $array2[$z + 1]
ConsoleWrite("$z= " & $z & "/ ubound array= " & UBound($array) & "/ isint: " & IsInt($z) & _
"/ int: " & Int($z) & "/ ubound array2= " & UBound($array2) & @LF)

Result

$z= 2/ ubound array= 1/ isint: 0/ int: 1/ ubound array2= 3

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Work for me correct as well.... but why does this code go wrong then ?

Dim $x = 4
Dim $y = 3
Dim $z = Ceiling($x / $y)
Dim $array[$z]
Dim $array2[$z + 1]
ConsoleWrite("$z= " & $z & "/ ubound array= " & UBound($array) & "/ isint: " & IsInt($z) & _
"/ int: " & Int($z) & "/ ubound array2= " & UBound($array2) & @LF)

Result

$z= 2/ ubound array= 1/ isint: 0/ int: 1/ ubound array2= 3

Here's your answer: Ceiling is returning a float (Why I don't know, but test it with IsFloat to confirm). Even more puzzling, the Int value is 1 while the float value is 2. This I also do not understand; they should obviously be the same. I don't know the implementation of Ceiling but it sounds like it's doing some very atypical things.

Dim $x = 4
Dim $y = 3
Dim $z = Ceiling($x / $y)
If IsFloat($z) Then MsgBox(4096, "", "It's a float")
MsgBox(4096, "", "Float: " & $z & @CRLF & "Int: " & Int($z))
Link to comment
Share on other sites

It returns a float because that is what the C function returns (double). I just assign it to the Return value.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...