Skip to content

Commit e224fbd

Browse files
committed
Add a few comments to clarify use of unusual values
1 parent 0a9d210 commit e224fbd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

projectm-eval/MemoryBuffer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ PRJM_EVAL_F* prjm_eval_memory_copy(projectm_eval_mem_buffer buffer,
114114
PRJM_EVAL_F* src,
115115
PRJM_EVAL_F* len)
116116
{
117+
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
117118
int offset_dest = (int) (*dest + 0.0001);
118119
int offset_src = (int) (*src + 0.0001);
119120
int count = (int) (*len + 0.0001);
@@ -183,6 +184,7 @@ PRJM_EVAL_F* prjm_eval_memory_set(projectm_eval_mem_buffer buffer,
183184
PRJM_EVAL_F* value,
184185
PRJM_EVAL_F* len)
185186
{
187+
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
186188
int offset_dest = (int) (*dest + 0.0001);
187189
int count = (int) (*len + 0.0001);
188190

projectm-eval/TreeFunctions.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ static uint32_t prjm_eval_genrand_int32(void)
170170

171171
if (!mti)
172172
{
173-
uint32_t s = 0x4141f00d;
173+
uint32_t s = 0x4141f00d; // Initial Mersenne Twister seed
174174
mt[0] = s & 0xffffffffUL;
175175
for (mti = 1; mti < N; mti++)
176176
{
@@ -360,6 +360,7 @@ prjm_eval_function_decl(mem)
360360
PRJM_EVAL_F* index_ptr = &ctx->value;
361361
invoke_arg(0, &index_ptr);
362362

363+
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
363364
PRJM_EVAL_F* mem_addr = prjm_eval_memory_allocate(ctx->memory_buffer, (int) (*index_ptr + 0.0001));
364365
if (mem_addr)
365366
{
@@ -377,6 +378,7 @@ prjm_eval_function_decl(freembuf)
377378

378379
invoke_arg(0, ret_val);
379380

381+
// Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
380382
prjm_eval_memory_free_block(ctx->memory_buffer, (int) (**ret_val + 0.0001));
381383
}
382384

0 commit comments

Comments
 (0)