Skip to content

Commit 996799f

Browse files
committed
All data types at once in Snowflake
1 parent 27576ec commit 996799f

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

samples/a8/graph_crossplatform/snowflake.pas

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
// Koch Snowflake
22
// https://en.wikipedia.org/wiki/Koch_snowflake
33

4-
// float16 186
5-
// real 197
6-
// single 237
4+
// For every supported data type, a separate unit with the same code is used.
5+
// Float16 186 ticks
6+
// Real 197 ticks
7+
// Single 237 ticks
78

9+
//FPC does not have Float16
10+
{$IFNDEF FPC}
11+
{$DEFINE HAS_FLOAT16}
12+
{$ENDIF}
813

914
uses crt, graph, sysutils,
15+
{$IFDEF HAS_FLOAT16}
16+
snowflake_unit_float16 in 'snowflake_unit_float16.pas',
17+
{$ENDIF}
1018
snowflake_unit_real in 'snowflake_unit_real.pas',
1119
snowflake_unit_single in 'snowflake_unit_single.pas';
1220

13-
procedure WaitForKey;
14-
begin
15-
repeat
16-
until KeyPressed;
17-
ReadKey;
18-
repeat
19-
until not KeyPressed;
20-
end;
21-
2221
procedure Snowflake;
2322

2423
const FLOAT_TYPES : array of String = [
25-
{$IFDEF FLOAT16} // TODO does not work yet
24+
{$IFDEF HAS_FLOAT16}
2625
'Float16',
2726
{$ENDIF}
2827
'Real',
@@ -45,20 +44,20 @@ procedure Snowflake;
4544
ticks := GetTickCount;
4645

4746
floatType:=FLOAT_TYPES[i];
48-
{$IFDEF Float16}
47+
{$IFDEF HAS_FLOAT16}
4948
if floatType = 'Float16' then snowflake_unit_float16.CreateKochSnowflake;
5049
{$ENDIF}
5150
if floatType = 'Real' then snowflake_unit_real.CreateKochSnowflake;
5251
if floatType = 'Single' then snowflake_unit_single.CreateKochSnowflake;
5352

5453
ticks := GetTickCount - ticks;
5554

56-
WaitForKey;
55+
ReadKey;
5756

5857
WriteLn('Koch Snowflake with type ''',floatType,'''.');
5958
Writeln('Time required: ', ticks,' ticks');
6059
WriteLn('Press any key to continue.');
61-
WaitForKey;
60+
ReadKey;
6261

6362
end;
6463

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
unit snowflake_unit_float16;
2+
3+
interface
4+
5+
procedure CreateKochSnowflake;
6+
7+
implementation
8+
9+
uses graph;
10+
11+
type
12+
TFloat = Float16;
13+
14+
{$I snowflake_unit.inc}
15+
16+
end.

0 commit comments

Comments
 (0)