/** math_pow : number -> number -> float <doc>Return power calculus</doc> **/ static value math_pow( value a, value b ) { tfloat r; val_check(a,number); val_check(b,number); r = (tfloat)pow(val_number(a),val_number(b)); if( (int)r == r && fabs(r) < (1 << 31) ) return alloc_best_int((int)r); return alloc_float(r); }
/** math_ceil : number -> int <doc>Return rounded-up integer</doc> **/ static value math_ceil( value n ) { switch( val_type(n) ) { case VAL_INT: case VAL_INT32: return n; case VAL_FLOAT: return alloc_best_int( (int)ceil(val_float(n)) ); default: neko_error(); } }
/** $int : any -> int? <doc>Convert the value to the corresponding integer or return [null]</doc> **/ static value builtin_int( value f ) { switch( val_type(f) ) { case VAL_FLOAT: #ifdef NEKO_WINDOWS return alloc_best_int((int)val_float(f)); #else // in case of overflow, the result is unspecified by ISO // so we have to make a module 2^32 before casting to int return alloc_int((unsigned int)fmod(val_float(f),4294967296.0)); #endif case VAL_STRING: { char *c = val_string(f), *end; int h; if( val_strlen(f) >= 2 && c[0] == '0' && (c[1] == 'x' || c[1] == 'X') ) { h = 0; c += 2; while( *c ) { char k = *c++; if( k >= '0' && k <= '9' ) h = (h << 4) | (k - '0'); else if( k >= 'A' && k <= 'F' ) h = (h << 4) | ((k - 'A') + 10); else if( k >= 'a' && k <= 'f' ) h = (h << 4) | ((k - 'a') + 10); else return val_null; } return alloc_best_int(h); } h = strtol(c,&end,10); return ( c == end ) ? val_null : alloc_best_int(h); } case VAL_INT: case VAL_INT32: return f; } return val_null; }
/** math_int : number -> int <doc>Return integer rounded down towards 0</doc> **/ static value math_int( value n ) { switch( val_type(n) ) { case VAL_INT: case VAL_INT32: return n; case VAL_FLOAT: { tfloat v = val_float(n); return alloc_best_int( (int)((n < 0) ? ceil(v) : floor(v)) ); } default: neko_error(); } }
//#define SSL_MODE_AUTO_RETRY 0x00000004L value _SSL_MODE_AUTO_RETRY() { return alloc_best_int(0x00000004L); }
value _SSL_set_mode(value ssl, value op) { long response = SSL_set_mode((SSL*) val_data(ssl), val_int(op)); return alloc_best_int(response); }
/** result_next : 'result -> object? <doc> Return the next row if available. A row is represented as an object, which fields have been converted to the corresponding Neko value (int, float or string). For Date and DateTime you can specify your own conversion function using [result_set_conv_date]. By default they're returned as plain strings. Additionally, the TINYINT(1) will be converted to either true or false if equal to 0. </doc> **/ static value result_next( value o ) { result *r; unsigned long *lengths = NULL; MYSQL_ROW row; val_check_kind(o,k_result); r = RESULT(o); row = mysql_fetch_row(r->r); if( row == NULL ) return val_null; { int i; value cur = alloc_object(NULL); r->current = row; for(i=0;i<r->nfields;i++) if( row[i] != NULL ) { value v; switch( r->fields_convs[i] ) { case CONV_INT: v = alloc_best_int(atoi(row[i])); break; case CONV_STRING: v = alloc_string(row[i]); if( r->conv_string != NULL ) v = val_call1(r->conv_string,v); break; case CONV_BOOL: v = alloc_bool( *row[i] != '0' ); break; case CONV_FLOAT: v = alloc_float(atof(row[i])); break; case CONV_BINARY: if( lengths == NULL ) { lengths = mysql_fetch_lengths(r->r); if( lengths == NULL ) val_throw(alloc_string("mysql_fetch_lengths")); } v = copy_string(row[i],lengths[i]); if( r->conv_bytes != NULL ) v = val_call1(r->conv_bytes,v); break; case CONV_DATE: if( r->conv_date == NULL ) v = alloc_string(row[i]); else { struct tm t; sscanf(row[i],"%4d-%2d-%2d",&t.tm_year,&t.tm_mon,&t.tm_mday); t.tm_hour = 0; t.tm_min = 0; t.tm_sec = 0; t.tm_isdst = -1; t.tm_year -= 1900; t.tm_mon--; v = val_call1(r->conv_date,alloc_int32((int)mktime(&t))); } break; case CONV_DATETIME: if( r->conv_date == NULL ) v = alloc_string(row[i]); else { struct tm t; sscanf(row[i],"%4d-%2d-%2d %2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); t.tm_isdst = -1; t.tm_year -= 1900; t.tm_mon--; v = val_call1(r->conv_date,alloc_int32((int)mktime(&t))); } break; default: v = val_null; break; } alloc_field(cur,r->fields_ids[i],v); } return cur; } }
/** $imult : any -> any -> int <doc>Multiply two integers</doc> **/ static value builtin_imult( value a, value b ) { return alloc_best_int( val_any_int(a) * val_any_int(b) ); }
/** $idiv : any -> any -> int <doc>Divide two integers. An error occurs if division by 0</doc> **/ static value builtin_idiv( value a, value b ) { if( val_any_int(b) == 0 ) neko_error(); return alloc_best_int( val_any_int(a) / val_any_int(b) ); }
/** $isub : any -> any -> int <doc>Subtract two integers</doc> **/ static value builtin_isub( value a, value b ) { return alloc_best_int( val_any_int(a) - val_any_int(b) ); }
/** $iadd : any -> any -> int <doc>Add two integers</doc> **/ static value builtin_iadd( value a, value b ) { return alloc_best_int( val_any_int(a) + val_any_int(b) ); }
/** buffer_get_length : 'buffer -> int <doc>Return the number of bytes currently stored into the buffer</doc> **/ static value buffer_get_length( value b ) { val_check_kind(b,k_buffer); return alloc_best_int(buffer_length((buffer)val_data(b))); }
value api_alloc_best_int(int arg1) { return alloc_best_int(arg1); }
static value tau_i64_to_int( value i ) { return alloc_best_int( (int) val_uint64(i) ); }