Implemented dumb float to bytes converter
This commit is contained in:
parent
0090dcdf93
commit
a21b0ac725
20
Makefile
20
Makefile
@ -1,17 +1,27 @@
|
||||
|
||||
default: sillymachine
|
||||
|
||||
sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads
|
||||
gnatmake ./src/sillymachine.adb
|
||||
floattobitshelper: ./src/floattobitshelper.c ./src/floattobitshelper.h
|
||||
gcc -c src/floattobitshelper.c -o floattobitshelper.o
|
||||
ar -crs floattobitshelper.a floattobitshelper.o
|
||||
|
||||
floatwin: ./src/floattobitshelper.c ./src/floattobitshelper.h
|
||||
x86_64-w64-mingw32-gcc -c src/floattobitshelper.c -o floatwin.o -lwinmm -lgdi32
|
||||
ar -crs floattobitshelper.a floatwin.o
|
||||
|
||||
|
||||
sillymachine: ./src/sillymachine.adb ./src/*.adb ./src/*.ads floattobitshelper
|
||||
gnatmake ./src/sillymachine.adb -largs -L./ -l:floattobitshelper.a
|
||||
|
||||
debug: ./src/sillymachine.adb ./src/*.adb ./src/*.ads
|
||||
gnatmake ./src/sillymachine.adb -o sillymachine-debug -g
|
||||
|
||||
win: ./src/sillymachine.adb ./src/*.adb ./src/*.ads
|
||||
win: ./src/sillymachine.adb ./src/*.adb ./src/*.ads floatwin
|
||||
|
||||
x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32
|
||||
x86_64-w64-mingw32-gnatmake src/sillymachine.adb -lwinmm -lgdi32 -largs -L./ -l:floattobitshelper.a
|
||||
|
||||
|
||||
all: sillymachine win
|
||||
|
||||
clean:
|
||||
rm *.o *.ali sillymachine.exe sillymachine sillymachine-debug
|
||||
rm *.o *.ali *.a sillymachine.exe sillymachine sillymachine-debug
|
||||
|
8
src/floattobitshelper.c
Normal file
8
src/floattobitshelper.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "floattobitshelper.h"
|
||||
#include <string.h>
|
||||
|
||||
int floattobitshelper(float x){
|
||||
int result = 0;
|
||||
memcpy(&result, &x, sizeof result);
|
||||
return result;
|
||||
}
|
1
src/floattobitshelper.h
Normal file
1
src/floattobitshelper.h
Normal file
@ -0,0 +1 @@
|
||||
int floattobitshelper(float x);
|
@ -180,8 +180,11 @@ package body Shardware is
|
||||
|
||||
function FToBytes (Number : Float) return ByteArr is
|
||||
ByteBuff : ByteArr (1 .. 4);
|
||||
Buffer : Integer := 0;
|
||||
begin
|
||||
raise Constraint_Error with "Not Implemented!";
|
||||
-- raise Constraint_Error with "Not Implemented!";
|
||||
Buffer := Integer(FloatToBitsHelper(C_float(Number)));
|
||||
ByteBuff := IToBytes(Buffer);
|
||||
return ByteBuff;
|
||||
end FToBytes;
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
with Ada.Sequential_IO;
|
||||
with Interfaces; use Interfaces;
|
||||
with Interfaces.C; use Interfaces.C;
|
||||
|
||||
package Shardware is
|
||||
|
||||
@ -29,6 +30,12 @@ package Shardware is
|
||||
function BytesToI (TheBytes : ByteArr) return Integer;
|
||||
function BytesToF (TheBytes : ByteArr) return Float;
|
||||
|
||||
function FloatToBitsHelper (X: C_float) return Int
|
||||
with
|
||||
Import => True,
|
||||
Convention => C,
|
||||
External_Name => "floattobitshelper";
|
||||
|
||||
function UToBytes (Number : Unsigned_32) return ByteArr;
|
||||
function IToBytes (Number : Integer) return ByteArr;
|
||||
function FToBytes (Number : Float) return ByteArr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user