ObjFW  Check-in [4560e88c45]

Overview
Comment:Always hash floats and doubles in big endian.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4560e88c45a4d4386661bdd128fe52bda53e844d357151203dc0bec4c3f3d352
User & Date: js on 2011-06-05 18:13:47
Other Links: manifest | tags
Context
2011-06-05
18:32
Add methods to read / write floats and doubles to OFStream. check-in: f31197a153 user: js tags: trunk
18:13
Always hash floats and doubles in big endian. check-in: 4560e88c45 user: js tags: trunk
18:07
Add methods for byte swapping floats and doubles. check-in: 2be6a03c5a user: js tags: trunk
Changes

Modified src/OFNumber.m from [e2396474e9] to [6768b46f61].

942
943
944
945
946
947
948
949
950
951
952







953
954
955
956
957
958
959







960
961
962
963
964
965
966
967
968
969
		return NO;
	}
}

- (uint32_t)hash
{
	uint32_t hash;
	size_t i;

	switch (type) {
	case OF_NUMBER_FLOAT:







		OF_HASH_INIT(hash);
		for (i = 0; i < sizeof(float); i++)
			OF_HASH_ADD(hash, ((char*)&value.float_)[i]);
		OF_HASH_FINALIZE(hash);

		return hash;
	case OF_NUMBER_DOUBLE:







		OF_HASH_INIT(hash);
		for (i = 0; i < sizeof(double); i++)
			OF_HASH_ADD(hash, ((char*)&value.double_)[i]);
		OF_HASH_FINALIZE(hash);

		return hash;
	default:
		return [self uInt32Value];
	}
}







<


|
>
>
>
>
>
>
>

<
|



|
>
>
>
>
>
>
>

<
|







942
943
944
945
946
947
948

949
950
951
952
953
954
955
956
957
958
959

960
961
962
963
964
965
966
967
968
969
970
971
972

973
974
975
976
977
978
979
980
		return NO;
	}
}

- (uint32_t)hash
{
	uint32_t hash;


	switch (type) {
	case OF_NUMBER_FLOAT:;
		union {
			float f;
			uint32_t i;
		} f;

		f.f = of_bswap_float_if_le(value.float_);

		OF_HASH_INIT(hash);

		OF_HASH_ADD_INT32(hash, f.i);
		OF_HASH_FINALIZE(hash);

		return hash;
	case OF_NUMBER_DOUBLE:;
		union {
			double d;
			uint64_t i;
		} d;

		d.d = of_bswap_double_if_le(value.double_);

		OF_HASH_INIT(hash);

		OF_HASH_ADD_INT64(hash, d.i);
		OF_HASH_FINALIZE(hash);

		return hash;
	default:
		return [self uInt32Value];
	}
}