Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer() function depends on SetFloatDelta() #1676

Open
cpyrgas opened this issue Jan 28, 2025 · 1 comment
Open

Integer() function depends on SetFloatDelta() #1676

cpyrgas opened this issue Jan 28, 2025 · 1 comment
Assignees

Comments

@cpyrgas
Copy link

cpyrgas commented Jan 28, 2025

As seen below, the result of Integer() function depends on the SetFloatDelta() setting :

FUNCTION Start() AS VOID
	SetFloatDelta(0.0)
	? "Float delta 0:"
	? Integer(0.1)   // 0, OK
	? Integer(0.001) // 0, OK

	SetFloatDelta(0.01)
	
	? "Float delta 0.01:"
	? Integer(0.1)   // 0, OK
	? Integer(0.001) // 1, wrong, 0 in VO

Problem is in this code of Integer() function:

FUNCTION Integer(nValue AS USUAL) AS USUAL
...
        IF nValue > 0.0 // this comparison depends on SetFloatDelta()
            result := Floor(nValue)
        ELSE
            result := Ceil(nValue)
        ENDIF

This can be fixed by casting the number to a REAL8 for the comparison, but we need to search for other similar occasions in the runtime.

@RobertvanderHulst
Copy link
Member

RobertvanderHulst commented Jan 28, 2025

When nValue is of type LONG or INT64 you do not want to compare with a fractional value at all.
I think the function should:

  • have a check for the type: LONG and INT64 should simply return the value
  • float should cast the value to a float and retrieve the Value part of the float to compare to the real8 value 0.0
  • Currency should compare with $0.0 and use a Floor() and Ceil() for Currency values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants