Recent

Author Topic: wish list: ifthen, tothepowerof, BGRA components  (Read 4670 times)

Blue1987

  • Full Member
  • ***
  • Posts: 165
wish list: ifthen, tothepowerof, BGRA components
« on: January 02, 2012, 02:38:05 pm »
i do not know if it is hte place where to write them, but I have a list of 3 features I would like to see 2 features implemented in fp and 1 in lazarus...

1a) a sintax like "ifthen(3>2,1,0)" as in delphi
1b) a function for "tothepowerof", something simple as "2^0.2" (every time I have to create a specific function for that)

2) the BGRA components included in the standard release of lazarus


:D




ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: wish list: ifthen, tothepowerof, BGRA components
« Reply #1 on: January 02, 2012, 02:49:02 pm »
Uses math;

function power(base,exponent : float) : float;

function ifthen(val:boolean;const iftrue:integer; const iffalse:integer= 0) :integer; inline; overload;
function ifthen(val:boolean;const iftrue:int64  ; const iffalse:int64 = 0)  :int64;   inline; overload;
function ifthen(val:boolean;const iftrue:double ; const iffalse:double =0.0):double;  inline; overload;

Edit: forgot one

Uses strutils;

Function IfThen(AValue: Boolean; const ATrue: string; const AFalse: string = ''): string; overload;
« Last Edit: January 02, 2012, 02:52:00 pm by ludob »

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: wish list: ifthen, tothepowerof, BGRA components
« Reply #2 on: January 02, 2012, 03:30:16 pm »
re: PowerOf - I would like an integer version of this, but I get around the issue by creating a lookup table and using that.  I'm only using power of 2, so my needs are much easier to deal with than the general case.

Bart

  • Hero Member
  • *****
  • Posts: 3452
    • Bart en Mariska's Webstek
Re: wish list: ifthen, tothepowerof, BGRA components
« Reply #3 on: January 02, 2012, 04:30:48 pm »
re: PowerOf - I would like an integer version of this, but I get around the issue by creating a lookup table and using that.  I'm only using power of 2, so my needs are much easier to deal with than the general case.

If you need it only for integers:
If you mean 2 as exponent, in that case use sqr(),
or if you mean 2 as base, in that case you maybe can use shl operator (2^n = 1 shl n).

Bart

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: wish list: ifthen, tothepowerof, BGRA components
« Reply #4 on: January 02, 2012, 05:09:08 pm »
Bart,
thanks for the hints. 
I need it for base.  I'll try that suggestion.

PascalDragon

  • Sr. Member
  • ****
  • Posts: 442
  • Compiler Developer
Re: wish list: ifthen, tothepowerof, BGRA components
« Reply #5 on: January 03, 2012, 03:38:24 pm »
1b) a function for "tothepowerof", something simple as "2^0.2" (every time I have to create a specific function for that)

The operator "**" already exists and is overloadable (see here: Overloadable Arithmetic Operators). Per default this operator is not overloaded though (thus not usable), but if you include the unit "math" it is overloaded and you can use it for floating point types and for integers.

Regards,
Sven