Raised This Month: $32 Target: $400
 8% 

Solved How can I use Huge Numbers?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-27-2021 , 05:06   How can I use Huge Numbers?
Reply With Quote #1

I'm working on a short plugin that translates a huge 64bit number into two other values by bit shifting. The process works great on a scientific calculator, but I have been unable to accomplish the task using Sourcemod.

The test code I developed will freeze the server and the client without providing any errors. I believe the number I'm using is too large for the '[EXTENSION] BigInteger compute with large numbers' that I installed. Link: https://forums.alliedmods.net/showthread.php?t=233938

Goal:
Given an input number of 5848670506169059306
It should produce a lowseed value of: 2021836778
It should also produce a highseed value of: 1361749718

Basically this is what I'm trying to achieve:
PHP Code:
    seed := 5848670506169059306
    high 
:= seed >> 32
    low 
:= (seed << 32) >> 32
    fmt
.Println("Seed is: "seed)
    
fmt.Println("Seed low is: "low)
    
fmt.Println("Seed high is: "high
However, that's not easy to do in Sourcemod. If the number is in fact too large for the BigInteger extension, how can I achieve the desired results without the extension?

Sourcemod code so far:
PHP Code:
#include <bigint>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo 
{
    
name "[TF2] Test of seed import and translation",
    
author "PC Gamer",
    
description "Test importing large number with BigInt",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.com"
}

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_seed"Command_TestBigInt);
}

public 
Action Command_TestBigInt(int clientint args)
{
    
char arg1[32];
    if (
args 1)
    {    
        
ReplyToCommand(client"seed <seed number>");
        
ReplyToCommand(client"Example: seed 5848670506169059306");    
        
        return 
Plugin_Handled;
    }
    
GetCmdArg(1arg1sizeof(arg1));
    
    
Handle hBigInt BigInt_CreateFromString(arg1);
    
Handle hNewBigIntLow BigInt_BitShiftRight(BigInt_BitShiftLeft(hBigInt32), 32);
    
Handle hNewBigIntHigh BigInt_BitShiftLeft(hBigInt32);

    
int lowseed BigInt_ToInt(hNewBigIntLow); //expected result 2021836778 
    
int highseed BigInt_ToInt(hNewBigIntHigh); //expected result: 1361749718    
    
    
PrintToChat(client"Input seed provided by client: %s"arg1);
    
PrintToChat(client"Seed translates into: lowseed: %i, highseed: %i"lowseedhighseed);    

    
delete hBigInt;
    
delete hNewBigIntLow;
    
delete hNewBigIntHigh;

    return 
Plugin_Handled;


Last edited by PC Gamer; 12-28-2021 at 04:44.
PC Gamer is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-28-2021 , 04:44   Re: How can I use Huge Numbers?
Reply With Quote #2

I'll mark this one as solved. For whatever reason the use of the BigInt_BitShiftLeft was causing my server to freeze. As a result, I used a different function of BigInt_BitAnd to achieve the desired result. Very weird.
PC Gamer is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode