Page 1 of 1

allow integers with floats operations

Posted: Sat Dec 06, 2008 3:06 pm
by Psychophanta
Ideal example:

Code: Select all

a.f=34.
b.l=33
c.f=(1-b&1)*a
Not even this works!!:

Code: Select all

b.l=33
c.f=Int(b&1)

Posted: Sat Dec 06, 2008 3:16 pm
by Michael Vogel
Agree, type casting would be cool :wink:

Code: Select all

 
a.f=34. 
b.l=33 
c.f=(float)(1-b&1)*a  
Even certain functions, like float(), double(), long() would be ok, this would be also a workaround for missing functions, like Integer() (oops, again the old story about integer math with abs(), int() etc. :oops: )

Posted: Sat Dec 06, 2008 3:29 pm
by Psychophanta
I would suggest no typecasting, but automatic evaluation depending on the destination type.

Posted: Sat Dec 06, 2008 4:31 pm
by akj
Casting can be implemented via small assembler routines. For example in http://www.purebasic.fr/english/viewtopic.php?t=32678 the casting of integer to float is handled with this function:

Code: Select all

Procedure.f Float(i.l)
  Protected Ar.f 
  !FILD dword [p.v_i] 
  !FSTP dword [p.v_Ar] 
  ProcedureReturn Ar 
EndProcedure
But the lack of casting and the lack of [non-conditional] Boolean expressions does highlight some fundamental shortcomings of PureBasic.

I would very much like to see development on PB 4.4 being all about 'Back to Basics'. Stop focussing for a while on the development of sophisticated library routines (welcome though they are) and concentrate on getting the core of PureBasic working properly, especially in the area of arithmetic expressions and mathematics. Virtually every program relies upon arithmetic being 100% reliable and highly convenient, but unfortunately this is not always the case with Pure Basic.

Here are some of the 'Back to Basic' areas that I feel need attention:

* Boolean expressions should be supported in assignment statements

* An expression should be allowed in the STEP clause of FOR

* FOR statements should work with all integer types, including quads

* Pow() and Log() and Log10() should all work at full double accuracy

* (Minor) The operator ' ^ ' should be available for the raising of powers e.g. 2^3

* Some fundamental missing funtions are missing, such as:
Max() Min() Sgn() String() and of course Abs() for integers

* SHAREd variable declarations within procedures should not need an spurious additional DEFINE statement when EnableExplicit is in effect

* Macros still need additional features to be fully useful

The one library that I think should still be improved in a major way is the Date library which I feel is reaching a crisis. It supports dates to only 19-Jan-2038. But this date is now very close. I can no longer use it with database related programs as (for example) the retirement date of many young adults now well exceeds this date. I ended up having to write my own comprehensive set of quad based date/time routines, but I would have preferred to be able to use the built-in routines instead.

Despite all the above negative comments, I really love PureBasic. It was one of the best purchases I ever made.

Posted: Sat Dec 06, 2008 4:48 pm
by milan1612
akj wrote:* Boolean expressions should be supported in assignment statements

* An expression should be allowed in the STEP clause of FOR

* FOR statements should work with all integer types, including quads

* Pow() and Log() and Log10() should all work at full double accuracy

* (Minor) The operator ' ^ ' should be available for the raising of powers e.g. 2^3

* Some fundamental missing funtions are missing, such as:
Max() Min() Sgn() String() and of course Abs() for integers
You're mentioning some very important features, the only thing I miss
in this list are unsigned types. Please Fred, focus one of the next versions on
improvements concerning the language itself. :P

Posted: Sat Dec 06, 2008 5:08 pm
by Psychophanta
akj wrote:Casting can be implemented via small assembler routines. For example in www.purebasic.fr/english/viewtopic.php?t=32678 the casting of integer to float is handled with this function:Code:
Procedure.f Float(i.l)
Protected Ar.f
!FILD dword [p.v_i]
!FSTP dword [p.v_Ar]
ProcedureReturn Ar
EndProcedure


But the lack of casting and the lack of [non-conditional] Boolean expressions does highlight some fundamental shortcomings of PureBasic.
:shock:
No need ASM for that:

Code: Select all

Procedure.f LtoF(i.l)
  ProcedureReturn i
EndProcedure
etc...