# ceilling / Array / ubound

## Recommended Posts

Hi,

I have some simple Questions to the following example:

Why returns ubound(\$array) in this script "1"? Returns ceilling really an integer? Because, isint(\$z) returns false? 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))

##### Share on other sites
• Developers

Hi,

I have some simple Questions to the following example:

Why returns ubound(\$array) in this script "1"? Returns ceilling really an integer? Because, isint(\$z) returns false? 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)

Live for the present,
Dream of the future,
Learn from the past. ##### 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 ##### 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 )

Live for the present,
Dream of the future,
Learn from the past. ##### 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 )

... 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

##### 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

Live for the present,
Dream of the future,
Learn from the past. ##### 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

##### 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

Live for the present,
Dream of the future,
Learn from the past. ##### 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))```
##### 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...

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...